需求:使用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. POJ 3104

    Drying Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7959   Accepted: 2014 Descriptio ...

  2. Java Socket文件上传

    客户端: import java.io.FileInputStream; import java.net.Socket; /** * Created by 290248126 on 14-5-11. ...

  3. TDD 用语

    OOP  封装  继承  多态 SOLID  SRP 单一职责  Single Responsibility Principle  OCP 开放封闭  Open/Close Principle  LS ...

  4. [转]Ubuntu 常用快捷键10个

    转自:http://www.linuxeden.com/html/news/20100613/103374.html 1.前一个后一个工作区的切换 如果你经常使用工作区,那你就可以用Ctrl + Al ...

  5. lintcode :搜索旋转排序数组

    题目 搜索旋转排序数组 假设有一个排序的按未知的旋转轴旋转的数组(比如,0 1 2 4 5 6 7 可能成为4 5 6 7 0 1 2).给定一个目标值进行搜索,如果在数组中找到目标值返回数组中的索引 ...

  6. 毕向东JAVA视频讲解(第六课)

    用java语言对现实生活中的事物进行描述. 通过类的形式来体现的. 怎么描述呢? 对于事物描述通常只关注两方面. 一个是属性,一个是行为. 只要明确该事物的属性和行为并定义在类中即可. 对象:其实就是 ...

  7. 利用Nginx搭建http和rtmp协议的流媒体服务器

    http://www.linuxidc.com/Linux/2013-02/79118.htm

  8. 汉诺塔算法的递归与非递归的C以及C++源代码

    汉诺塔(又称河内塔)问题其实是印度的一个古老的传说. 开天辟地的神勃拉玛(和中国的盘古差不多的神吧)在一个庙里留下了三根金刚石的棒,第一根上面套着64个圆的金片,最大的一个在底下,其余一个比一 个小, ...

  9. HackDemo.java

    import java.io.*; import java.awt.*; public class HackDemo{ public static void main(String args[]) t ...

  10. 31. Next Permutation

    题目: Implement next permutation, which rearranges numbers into the lexicographically next greater per ...