微信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. Transact-SQL

    Transact-SQL(又称T-SQL),是在Microsoft SQL Server和Sybase SQL Server上的ANSI SQL实现,与Oracle的PL/SQL性质相近(不只是实现A ...

  2. html5 canvas 移动小方块

    <!doctype html> <html> <head> <meta charset="utf-8"> <title> ...

  3. C++builder XE10 终于支持类内变量初始化了

    Win32终于支持类内变量初始化了,C++11 用bcc32C编译器  llvm CLang.还支持Unicode 中文汉字 变量名. 用经典的bcc32编译还是不支持! class TPerson ...

  4. Android NDK调试C++源码(转)

    [原创文章,转载请保留或注明出处,http://download.csdn.net/download/bigmaxim/5474055] 1. 相关软件 adt-bundle-windows-x86. ...

  5. Oracle中INT、FLOAT、NUMBER区别

    Oracle里的int等于number(长度,0) float也类似,number要定义小数部分的位数,而float不用定义后边小数有几位  因为NUMBER要确定长度,后边确定小数位. 所以,如果不 ...

  6. Expression<Func<T,TResult>>和Func<T,TResult> 与AOP与WCF

    1>>Expression<Func<T,TResult>>和Func<T,TResult>http://www.cnblogs.com/xcsn/p/ ...

  7. 表单input按钮在各浏览器之间的兼容性

    从网上看了这篇关于表单input按钮的浏览器兼容性问题,总结的还不错,所以copy下来学习下. input按钮在各个浏览器之间的兼容性问题,看下边这段代码: input.item { backgrou ...

  8. NodeJs使用Mysql模块实现事务处理

    依赖模块: 1. mysql:https://github.com/felixge/node-mysql npm install mysql --save 2. async:https://githu ...

  9. Linux 基本权限(一)

    1. 权限概念 root@hang:/home# ll 总用量 20#文件权限 链接数量 文件所有者 所属用户组 容量大小B 创建(修改)时间 文件名 drwxr-xr-x root root 11月 ...

  10. Android中全局Application的onCreate多次调用问题

    String processName = OsUtils.getProcessName(this, android.os.Process.myPid()); if (processName != nu ...