一起学android之底部菜单TabHost的实现(9)
来源:互联网 发布:进出口价格弹性算法 编辑:程序博客网 时间:2024/05/21 06:42
/<span style="font-size:24px;">res/values/styles.xml代码:</span>
<resources><style name="main_tab_bottom"> <item name="android:textSize">12.0dip</item> <item name="android:textColor">#ffffffff</item> <item name="android:ellipsize">marquee</item> <item name="android:gravity">center_horizontal</item> <item name="android:paddingTop">5.0dip</item> <item name="android:layout_width">fill_parent</item> <item name="android:layout_height">wrap_content</item> <item name="android:button">@null</item> <item name="android:singleLine">true</item> <item name="android:drawablePadding">2.0dip</item> <item name="android:layout_weight">1.0</item> </style> </resources>
layout布局:
<TabHost xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/tabhost" android:layout_width="fill_parent" android:layout_height="fill_parent" > <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" > <FrameLayout android:id="@+id/msg_title" android:layout_width="fill_parent" android:layout_height="wrap_content" android:visibility="gone" > <!-- VISIBLE:设置控件可见INVISIBLE:设置控件不可见GONE:设置控件隐藏 --> <TextView android:id="@+id/tv_wb" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@drawable/titlebar_lightgray_bg" > </TextView> </FrameLayout> <FrameLayout android:id="@android:id/tabcontent" android:layout_width="fill_parent" android:layout_height="0.0dip" android:layout_weight="1.0" /> <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_weight="0.0" android:visibility="gone" /> <RadioGroup android:id="@+id/radio" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="@drawable/maintab_toolbar_bg" android:gravity="center_vertical" android:orientation="horizontal" > <RadioButton android:id="@+id/radio_button0" android:layout_marginTop="2.0dip" android:drawableTop="@drawable/icon_1_n" android:tag="radio_button0" android:text="首页" style="@style/main_tab_bottom" /> <RadioButton android:id="@+id/radio_button1" android:layout_marginTop="2.0dip" android:drawableTop="@drawable/icon_2_n" android:tag="radio_button1" android:text="信息" style="@style/main_tab_bottom"/> <RadioButton android:id="@+id/radio_button2" android:layout_marginTop="2.0dip" android:drawableTop="@drawable/icon_3_n" android:tag="radio_button2" android:text="名片" style="@style/main_tab_bottom" /> <RadioButton android:id="@+id/radio_button3" android:layout_marginTop="2.0dip" android:drawableTop="@drawable/icon_4_n" android:tag="radio_button3" android:text="查询" style="@style/main_tab_bottom"/> <RadioButton android:id="@+id/radio_button4" android:layout_marginTop="2.0dip" android:drawableTop="@drawable/icon_5_n" android:tag="radio_button4" android:text="更多" style="@style/main_tab_bottom" /> </RadioGroup> </LinearLayout></TabHost>
java代码:
/* * Android菜单之底部TabHost,布局文件main.xml */public void setTabHost(){tabHost=this.getTabHost();TabSpec tabSpec1=tabHost.newTabSpec("TAB_1").setIndicator("TAB_1");//tabSpec1.setContent(new Intent(MainActivity.this,Activity1.class));//第一个activitytabHost.addTab(tabSpec1);TabSpec tabSpec2=tabHost.newTabSpec("TAB_2").setIndicator("TAB_2");//tabSpec2.setContent(new Intent(MainActivity.this,Activity2.class));//第二个activitytabHost.addTab(tabSpec2);TabSpec tabSpec3=tabHost.newTabSpec("TAB_3").setIndicator("TAB_3");//tabSpec3.setContent(new Intent(MainActivity.this,Activity3.class));//第三个activitytabHost.addTab(tabSpec3);TabSpec tabSpec4=tabHost.newTabSpec("TAB_4").setIndicator("TAB_4");//tabSpec4.setContent(new Intent(MainActivity.this,Activity4.class));//第四个activitytabHost.addTab(tabSpec4);TabSpec tabSpec5=tabHost.newTabSpec("TAB_5").setIndicator("TAB_5");//tabSpec5.setContent(new Intent(MainActivity.this,Activity5.class));//第五个activitytabHost.addTab(tabSpec5);//查找控件radioGroup=(RadioGroup) findViewById(R.id.radio);//为菜单按钮添加事件radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {@Overridepublic void onCheckedChanged(RadioGroup group, int checkedId) {// TODO Auto-generated method stubswitch (checkedId) {case R.id.radio_button0:tabHost.setCurrentTabByTag("TAB_1");Toast.makeText(context, "进入第一个界面", Toast.LENGTH_SHORT).show();break;case R.id.radio_button1:tabHost.setCurrentTabByTag("TAB_2");Toast.makeText(context, "进入第二个界面", Toast.LENGTH_SHORT).show();break;case R.id.radio_button2:tabHost.setCurrentTabByTag("TAB_3");Toast.makeText(context, "进入第三个界面", Toast.LENGTH_SHORT).show();break;case R.id.radio_button3:tabHost.setCurrentTabByTag("TAB_4");Toast.makeText(context, "进入第四个界面", Toast.LENGTH_SHORT).show();break;case R.id.radio_button4:tabHost.setCurrentTabByTag("TAB_5");Toast.makeText(context, "进入第五个界面", Toast.LENGTH_SHORT).show();break;default:break;}}});}
效果图:
0 1
- 一起学android之底部菜单TabHost的实现(9)
- Android 底部菜单的实现(TabHost)
- android之实现底部TabHost
- android之实现底部TabHost
- TabHost实现底部菜单
- 滑动菜单解决方案之三:使用TabHost控件实现微信界面的底部菜单效果
- TabHost 之实现底部
- 如何利用Android TabHost+ActivityGroup+Broadcast实现类似于iPhone的底部菜单
- TabHost的底部实现
- Android底部菜单栏(tabhost实现)
- 一起学android之选项菜单创建(4)
- <Android 基础(三十三)> TabHost ~ 仿微信底部菜单
- Android底部菜单的实现
- TabHost、RadioGroup实现底部菜单导航
- TabHost、RadioGroup、ToolBar实现底部菜单导航
- TabHost+TabWidget+FrameLayout实现底部菜单页面
- 底部菜单栏实现之TabHost
- 一起学android之子菜单的创建(6)
- leetcode Sort Colors java实现
- 电商项目开发总结
- Source Insight中通过编辑宏实现对函数头和文件头的自动添加
- 在Windows操作系统下通过PL/SQL连接到VM中Linux安装的Oracle
- 获取浏览器收藏夹的标签
- 一起学android之底部菜单TabHost的实现(9)
- mapreduce程序编写(大数据学习跟进)
- Android四大组件的生命周期
- MongoDB 只允许本地访问
- adobe pdf 在线打开
- windows 与Linux之间的文件传输
- Eclipse Maven Install
- mfsmount disabled fuse library is too old or not installed
- 谁说女程序猿不能穿裙子啊!