微信Tab预览效果:

思路:

1、用TabHost+RadioGroup搭建基本布局,以RadioGroup代替TabWidget

2、设置按钮和文字的的样式和selector

3、创建相应的Activity

4、实现按钮和内容切换

布局:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@android:id/tabhost"
> <LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
></FrameLayout> <!-- 隐藏TabWidget -->
<TabWidget
android:id="@android:id/tabs"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
</TabWidget> <!-- 视觉上,用单选按钮替代TabWidget -->
<RadioGroup
android:id="@+id/main_radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/mmfooter_bg"
android:paddingTop="8dp"
android:orientation="horizontal"
>
<RadioButton
android:id="@+id/tab_icon_weixin"
android:checked="true"
android:textColor="@color/tab_text"
android:drawableTop="@drawable/tab_weixin"
android:text="@string/radio1_text"
style="@style/tab_button_bg"
/> <RadioButton
android:id="@+id/tab_icon_address"
android:textColor="@color/tab_text"
android:drawableTop="@drawable/tab_address"
android:text="@string/radio2_text"
style="@style/tab_button_bg"
/> <RadioButton
android:id="@+id/tab_icon_friend"
android:textColor="@color/tab_text"
android:drawableTop="@drawable/tab_frd"
android:text="@string/radio3_text"
style="@style/tab_button_bg"
/> <RadioButton
android:id="@+id/tab_icon_setting"
android:textColor="@color/tab_text"
android:drawableTop="@drawable/tab_set"
android:text="@string/radio4_text"
style="@style/tab_button_bg"
/> </RadioGroup>
</LinearLayout>
</TabHost>

按钮样式:

    <!-- 按钮文字样式 -->
<style name="tab_text_color">
<item name="android:textColor">@color/tab_text</item>
<item name="android:textSize">12dp</item>
<!-- 从左向右跑马灯效果 -->
<item name="android:ellipsize">marquee</item>
<!-- 单行显示 -->
<item name="android:singleLine">true</item>
</style> <!-- 按钮样式 -->
<style name="tab_button_bg">
<item name="android:textAppearance">@style/tab_text_color</item>
<item name="android:gravity">center</item>
<item name="android:background">@drawable/tab_bg</item>
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:button">@null</item>
<item name="android:layout_weight">1</item>
</style>

按钮图片selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_enabled="true" android:state_checked="true" android:drawable="@drawable/tab_address_pressed"></item>
<item android:drawable="@drawable/tab_address_normal"></item>
</selector>

按钮文字selector

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/white"></item>
<item android:color="@color/grey"></item>
</selector>

程序:

public class MainActivity extends TabActivity{
private TabHost tabhost;
private RadioGroup main_radiogroup;
private RadioButton tab_icon_weixin, tab_icon_address, tab_icon_friend,tab_icon_setting;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.demo); //获取按钮
main_radiogroup = (RadioGroup) findViewById(R.id.main_radiogroup); tab_icon_weixin = (RadioButton) findViewById(R.id.tab_icon_weixin);
tab_icon_address = (RadioButton) findViewById(R.id.tab_icon_address);
tab_icon_friend = (RadioButton) findViewById(R.id.tab_icon_friend);
tab_icon_setting = (RadioButton) findViewById(R.id.tab_icon_setting); //往TabWidget添加Tab
tabhost = getTabHost();
tabhost.addTab(tabhost.newTabSpec("tag1").setIndicator("0").setContent(new Intent(this,Activity1.class)));
tabhost.addTab(tabhost.newTabSpec("tag2").setIndicator("1").setContent(new Intent(this,Activity2.class)));
tabhost.addTab(tabhost.newTabSpec("tag3").setIndicator("2").setContent(new Intent(this,Activity3.class)));
tabhost.addTab(tabhost.newTabSpec("tag4").setIndicator("3").setContent(new Intent(this,Activity4.class))); //设置监听事件
checkListener checkradio = new checkListener();
main_radiogroup.setOnCheckedChangeListener(checkradio);
} //监听类
public class checkListener implements OnCheckedChangeListener{
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
// TODO Auto-generated method stub
//setCurrentTab 通过标签索引设置当前显示的内容
//setCurrentTabByTag 通过标签名设置当前显示的内容
switch(checkedId){
case R.id.tab_icon_weixin:
tabhost.setCurrentTab(0);
//或
//tabhost.setCurrentTabByTag("tag1");
break;
case R.id.tab_icon_address:
tabhost.setCurrentTab(1);
break;
case R.id.tab_icon_friend:
tabhost.setCurrentTab(2);
break;
case R.id.tab_icon_setting:
tabhost.setCurrentTab(3);
break;
} }
} }

实例下载>>>>>

相关的文章:

Android:TabHost实现Tab切换

Android:res之selector背景选择器

Android:Activity之间跳转和参数传递

Android:布局实例之模仿微信Tab的更多相关文章

  1. [转]Android:布局实例之模仿QQ登录界面

    Android:布局实例之模仿QQ登录界面 预览图: 准备: 1.找到模仿对象 QQ登陆界面UI下载>>>>> 2.导入工程 3.查看布局结构和使用控件 其对应效果图分布 ...

  2. Android:布局实例之模仿QQ登录界面

    预览图: 准备: 1.找到模仿对象 QQ登陆界面UI下载>>>>> 2.导入工程 3.查看布局结构和使用控件 其对应效果图分布为 4.分析样式选择器 下拉箭头2种样式:点 ...

  3. Android:布局实例之模仿京东登录界面

    预览图及布局结构参考: 布局: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout ...

  4. Android Studio精彩案例(三)《模仿微信ViewPage+Fragment实现方式二》

    转载本专栏文章,请注明出处,尊重原创 .文章博客地址:道龙的博客 写在前面的话:此专栏是博主在工作之余所写,每一篇文章尽可能写的思路清晰一些,属于博主的"精华"部分,不同于以往专栏 ...

  5. android本地数据库,微信数据库WCDB for Android 使用实例

    android本地数据库,微信数据库WCDB for Android 使用实例 Home · Tencent/wcdb Wikihttps://github.com/Tencent/wcdb/wiki ...

  6. android actionbar viewpager 实现类微信主界面布局

    1 Activity public class MainActivity extends FragmentActivity { private ViewPager pager; private Act ...

  7. 自定义控件(模仿微信ToggleButton控件)

    弄过android开发的都知道,系统有一个默认的ToggleButton,但很多人都觉得他很难看,当然也包括我.如果你感觉他不难看,那你就继续使用系统的吧,这篇文章对你来说是多余的了. 今天来写一个模 ...

  8. [Android] Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单

    Android 使用 FragmentTabHost + Fragment 实现 微信 底部菜单 利用FragmentTabHost实现底部菜单,在该底部菜单中,包括了4个TabSpec,每个TabS ...

  9. 【转】 Android常用实例—Alert Dialog的使用

    Android常用实例—Alert Dialog的使用 AlertDialog的使用很普遍,在应用中当你想要用户做出“是”或“否”或者其它各式各样的选择时,为了保持在同样的Activity和不改变用户 ...

随机推荐

  1. C++的引用类型的变量到底占不占用内存空间?

    ——by  karottc 分析一下 C++ 里面的引用类型(例如: int &r = a;  )中的 r 变量是否占用内存空间呢?是否和  int *p = &a;  中的 p 变量 ...

  2. windows分屏

    一.准备 主机.显示屏A.显示屏B.DVI连接线2根 二.操作步骤 1.使用DVI连接线将显示屏A连接到主机上,开机进入windows系统(演示用的是win 7)(若已连接,请跳到第2步.基本上这一步 ...

  3. SQL Server数学函数

    数学函数 1.计算绝对值ABS ABS函数对一个数值表达式结果计算绝对值(bit数据类型除外),返回整数. 语法结构: ABS(数值表达式) 返回值:与数值表达式类型一致的数据 示例: ) --输出 ...

  4. ACM 中常用的算法有哪些? 2014-08-21 21:15 40人阅读 评论(0) 收藏

    ACM 中常用的算法有哪些?作者: 张俊Michael 网络上流传的答案有很多,估计提问者也曾经去网上搜过.所以根据自己微薄的经验提点看法. 我ACM初期是训练编码能力,以水题为主(就是没有任何算法, ...

  5. printf函数重定向

    printf函数底层会调用fputc函数 /*重定向c库函数printf到USART1*/ int fputc(int ch, FILE *f) { /*发送一个字节数据USART1 */ USART ...

  6. ThinkPad X200s 安装 Mac OSX

    ===================先说一下注意事项================== 无论任何安装方法(U盘.光盘)不能进入安装界面,或者鼠标无法移动.那就在变色龙引导界面加入以下代码 cpus ...

  7. 使用Map List 封装json数据

    <dependency> <groupId>net.sf.json-lib</groupId> <artifactId>json-lib</art ...

  8. How Tomcat Works(十一)

    本文接下来分析tomcat的类载入器,tomcat需要实现一个自定义的载入器,而不能使用系统类载入器 (1)限制serlvet访问当前运行的java虚拟机中环境变量CLASSPATH指明的路径下的所有 ...

  9. 【PAT】1020. Tree Traversals (25)

    Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and i ...

  10. jsp页面加载readyState的五种状态根据我们状态添加进度条

    这段代码放在页面最下面 原文如下: document.onreadystatechange = subSomething;//当页面加载状态改变的时候执行这个方法. function subSomet ...