需求:使用TabHost & RadioGroup实现底部菜单栏;

效果图:

实现分析:

1.目录结构:

代码实现:

1. activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<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="@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/main_radiogroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@drawable/tab_widget_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:padding="2dip" > <RadioButton
android:id="@+id/RadioButton0"
style="@style/tab_item_background"
android:checked="true"
android:drawableTop="@drawable/tab_icon1"
android:text="主页" /> <RadioButton
android:id="@+id/RadioButton1"
style="@style/tab_item_background"
android:drawableTop="@drawable/tab_icon2"
android:text="关于" /> <RadioButton
android:id="@+id/RadioButton2"
style="@style/tab_item_background"
android:drawableTop="@drawable/tab_icon3"
android:text="设置" /> <RadioButton
android:id="@+id/RadioButton3"
style="@style/tab_item_background"
android:drawableTop="@drawable/tab_icon4"
android:text="搜索" /> <RadioButton
android:id="@+id/RadioButton4"
style="@style/tab_item_background"
android:drawableTop="@drawable/tab_icon5"
android:text="更多" />
</RadioGroup>
</LinearLayout> </TabHost>

2. styles.xml

    <style name="item_tab_text_style">
<item name="android:textSize">10.0dip</item>
<item name="android:textColor">#ffffffff</item>
<item name="android:ellipsize">marquee</item>
<item name="android:singleLine">true</item>
</style> <style name="tab_item_background">
<item name="android:textAppearance">@style/item_tab_text_style</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:background">@drawable/tab_background_selector</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:drawablePadding">3.0dip</item>
<item name="android:layout_weight">1.0</item>
</style>

3. MainActivity.java

package com.jjc.demo;

import com.jjc.demo.Constant.ConValue;

import android.app.TabActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.RadioGroup;
import android.widget.RadioGroup.OnCheckedChangeListener;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec; public class MainActivity extends TabActivity { //定义TabHost对象
private TabHost mTabHost; //定义RadioGroup对象
private RadioGroup radioGroup; @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main); initView();
initData();
} /**
* 初始化组件
*/
private void initView() {
// 实例化TabHost对象,得到TabHost
mTabHost = getTabHost(); // 得到Activity的个数
int count = ConValue.mTabClassArray.length; for (int i = 0; i < count; i++) {
//为每一个Tab按钮设置图标、文字和内容
TabSpec tabSpec = mTabHost.newTabSpec(ConValue.mTextViewArray[i]).setIndicator(ConValue.mTextViewArray[i]).setContent(getTabItemIntent(i));
//将Tab按钮添加进Tab选项卡中
mTabHost.addTab(tabSpec);
} //实例化RadioGroup
radioGroup = (RadioGroup) findViewById(R.id.main_radiogroup);
} private void initData(){
// 给radioGroup设置监听事件
radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener(){ @Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.RadioButton0:
mTabHost.setCurrentTabByTag(ConValue.mTextViewArray[0]);
break;
case R.id.RadioButton1:
mTabHost.setCurrentTabByTag(ConValue.mTextViewArray[1]);
break;
case R.id.RadioButton2:
mTabHost.setCurrentTabByTag(ConValue.mTextViewArray[2]);
break;
case R.id.RadioButton3:
mTabHost.setCurrentTabByTag(ConValue.mTextViewArray[3]);
break;
case R.id.RadioButton4:
mTabHost.setCurrentTabByTag(ConValue.mTextViewArray[4]);
break;
default:
break;
} }});
} /**
* 给Tab选项卡设置内容(每个内容是一个Activity)
*/
private Intent getTabItemIntent(int index) {
Intent intent = new Intent(this, ConValue.mTabClassArray[index]);
return intent;
}
}

总结:android:textAppearance设置文字外观。如 “?android:attr/textAppearanceLargeInverse”这里引用的是系统自带的一个外观,?表示系统是否有这种外观,否则使用默认的外观。

代码:http://pan.baidu.com/s/1nh9X8

底部菜单栏(二) TabHost & RadioGroup 实现的更多相关文章

  1. 完美逆向百度手机助手5.0底部菜单栏 - Android Tabhost 点击动画

    先看看百度手机助手5.0的样子: 发现他是用一个CustomTabHost.java来实现底部TabHost点击效果的,很漂亮,点击Tab的时候文字会上跑,图片会从底部跑出来的一个小动画. 下面我用自 ...

  2. 【Android UI设计与开发】5.底部菜单栏(二)使用Fragment实现底部菜单栏

    既然 Fragment 取代了TabActivity,当然 TabActivity 的能实现的菜单栏,Fragment 当然也能实现.主要其实就是通过菜单栏的点击事件切换 Fragment 的显示和隐 ...

  3. 底部菜单栏(一) TabHost实现

    需求:使用TabHost实现底部菜单栏: 效果图: 实现分析: 1.目录结构: 代码实现: 1.activity_main.xml <?xml version="1.0" e ...

  4. 【Android开发笔记】底部菜单栏 FragmentTabHost

    公司项目,需求本来是按照谷歌官方指南写的,菜单栏设计成在导航栏下方 结果呢,审评时,BOSS为了和iOS统一,改成了底部菜单栏(标准结局),我只能呵呵呵呵呵呵呵 查了查资料发现实现底部菜单栏用的是Fr ...

  5. FragmentTabHost+FrameLayout实现底部菜单栏

    现在一般的app都使用底部菜单栏,那具体怎么实现的呢!我们就来看看 首先给大家展示一下布局文件 1 <LinearLayout xmlns:android="http://schema ...

  6. 我的Android之路——底部菜单栏的实现

    底部菜单栏的实现 底部菜单栏两种实现方法:ViewPager:可滑动的界面:Fragment:固定的界面. 首先,页面布局,在除去顶部toolbar之后,将主界面分为两部分,一部分为界面显示区,另一部 ...

  7. Android底部菜单栏+顶部菜单

    底部菜单栏+顶部菜单(wechat)demo http://blog.csdn.net/evankaka/article/details/44121457 底部菜单demo http://blog.c ...

  8. 【转】【Android UI设计与开发】第07期:底部菜单栏(二)Fragment的详细介绍和使用方法

    原始地址:http://blog.csdn.net/yangyu20121224/article/category/1431917/1 由于TabActivity在Android4.0以后已经被完全弃 ...

  9. 底部菜单栏(三)Fragment+FragmentTabHost实现仿新浪微博底部菜单栏

    一.实现效果图 二.项目工程结构 三.详细代码编写 1.主tab布局界面,main_tab_layout: 双击代码全选 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

随机推荐

  1. Unity3D之Vector3.Dot和Vector3.Cross的使用

    在unity3d中,Vector3.Dot表示求两个向量的点积;Vector3.Cross表示求两个向量的叉积. 点积计算的结果为数值,而叉积计算的结果为向量.两者要注意区别开来. 在几何数学中: 1 ...

  2. linux源码阅读笔记 #define 语句的妙用

    #define 语句用于宏定义,在c中,我们可以用其实现函数的功能.如下语句 #define test(a,b)  a>b?a:b 很显然,这是一个比较大小的语句.这里a,b相当于函数中的参数. ...

  3. hdoj 2544 最短路

    题目传送:http://acm.hdu.edu.cn/showproblem.php?pid=2544 分析:Dijkstra算法 //2013-10-30 10:01:25 Accepted 254 ...

  4. [z]CAP原理和BASE思想

    分布式领域CAP理论,Consistency(一致性), 数据一致更新,所有数据变动都是同步的Availability(可用性), 好的响应性能Partition tolerance(分区容错性) 可 ...

  5. android MD5

    public static String MD5(String str) { MessageDigest md5 = null; try { md5 = MessageDigest.getInstan ...

  6. 简单的自绘CListBox,重载虚MeasureItem和DrawItem这两个虚函数

    [cpp] view plain copy //例如CNewListBox继承自CListBox,重载虚MeasureItem和DrawItem这两个虚函数,代码如下: void CNewListBo ...

  7. PHP获取服务器的mac地址类

    PHP获取服务器的mac地址类,不是客户端的. <?php class GetMacAddr{ var $return_array = array(); // 返回带有MAC地址的字串数组 va ...

  8. Drawit插件

    gvim用不了画矩形的功能,只能在vim下用 \di,\ds开始/结束画图(Vim里\按键没有被映射,可以做leader按键) 用鼠标选择一块之后,\b画矩形,\e画椭圆 选单行\a画箭头,\l画线 ...

  9. 内核MKDEV(MAJOR, MINOR)宏

    版本:linux-2.6.24.4宏:    MKDEV(MAJOR, MINOR);  说明: 获取设备在设备表中的位置.        MAJOR   主设备号        MINOR   次设 ...

  10. MyEclipse开发WebService教程

    . 创建一个 webService 工程. 2. 创建一个普通 Java 类   3. 创建 webService 服务端 HelloJaxwsDelegate.java 的源代码如下:   4. 导 ...