Android之TabHost组件美化

先看效果图:

1.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"
     android:background="@drawable/mnv"
     >
     <LinearLayout
         android:orientation="vertical"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent">
         <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_tab"
             android:background="@drawable/maintab_toolbar_bg"
             android:orientation="horizontal"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:gravity="center_vertical"
             android:layout_gravity="bottom">
             <RadioButton
                 android:layout_marginTop="0.5dip"
                 android:text="@string/main_home"
                 android:drawableTop="@drawable/icon_0_n"
                 android:id="@+id/radio_button0"
                 style="@style/main_tab_bottom"/>
             <RadioButton
                 android:layout_marginTop="0.5dip"
                 android:text="@string/main_news"
                 android:drawableTop="@drawable/icon_1"
                 android:id="@+id/radio_button1"
                 style="@style/main_tab_bottom"/>
             <RadioButton
                 android:layout_marginTop="0.5dip"
                 android:text="@string/main_shou_cang"
                 android:drawableTop="@drawable/icon_3_n"
                 android:id="@+id/radio_button2"
                 style="@style/main_tab_bottom"/>
             <RadioButton
                 android:layout_marginTop="1.0dip"
                 android:text="@string/main_my_info"
                 android:drawableTop="@drawable/icon_4_n"
                 android:id="@+id/radio_button3"
                 style="@style/main_tab_bottom"/>
             <RadioButton
                 android:layout_marginTop="0.5dip"
                 android:text="@string/more"
                 android:drawableTop="@drawable/icon_5_n"
                 android:id="@+id/radio_button4"
                 style="@style/main_tab_bottom"/>
         </RadioGroup>
     </LinearLayout>
 </TabHost>

2.MainTabActivity.java代码:

package com.jun.activity;
 import android.app.TabActivity;
 import android.content.Intent;
 import android.os.Bundle;
 import android.view.Window;
 import android.widget.RadioGroup;
 import android.widget.TabHost;
 import android.widget.RadioGroup.OnCheckedChangeListener;
 import android.widget.Toast;
 public class MainTabActivity extends TabActivity implements OnCheckedChangeListener{
     private RadioGroup mainTab;
     private TabHost tabhost;
     private Intent iHome;
     private Intent iNews;
     private Intent iInfo;
     private Intent iSearch;
     private Intent iMore;

     @Override
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         setContentView(R.layout.main);
         mainTab=(RadioGroup)findViewById(R.id.main_tab);
         mainTab.setOnCheckedChangeListener(this);
         tabhost = getTabHost();
 //        在此进行Intent的初始化,设置Intent将传进那个Activity
 //        iHome = new Intent(this, HomeActivity.class);
 //        tabhost.addTab(tabhost.newTabSpec("iHome")
 //                .setIndicator(getResources().getString(R.string.main_home), getResources().getDrawable(R.drawable.icon_1_n))
 //                .setContent(iHome));
 //
 //        iNews = new Intent(this, NewsActivity.class);
 //        tabhost.addTab(tabhost.newTabSpec("iNews")
 //                .setIndicator(getResources().getString(R.string.main_news), getResources().getDrawable(R.drawable.icon_2_n))
 //                .setContent(iNews));
 //
 //        iInfo = new Intent(this, MyInfoActivity.class);
 //        tabhost.addTab(tabhost.newTabSpec("iInfo")
 //                .setIndicator(getResources().getString(R.string.main_my_info), getResources().getDrawable(R.drawable.icon_3_n))
 //                .setContent(iInfo));
 //
 //        iSearch = new Intent(this,SearchActivity.class);
 //        tabhost.addTab(tabhost.newTabSpec("iSearch")
 //                .setIndicator(getResources().getString(R.string.menu_search), getResources().getDrawable(R.drawable.icon_4_n))
 //                .setContent(iSearch));
 //
 //        iMore = new Intent(this, MoreActivity.class);
 //         tabhost.addTab(tabhost.newTabSpec("iMore")
 //                    .setIndicator(getResources().getString(R.string.more), getResources().getDrawable(R.drawable.icon_5_n))
 //                    .setContent(iMore));
     }

     @Override
     public void onCheckedChanged(RadioGroup group, int checkedId) {
         switch(checkedId){
         case R.id.radio_button0:
             Toast.makeText(MainTabActivity.this,"button0",Toast.LENGTH_SHORT).show();
             break;
         case R.id.radio_button1:
             Toast.makeText(MainTabActivity.this,"button1",Toast.LENGTH_SHORT).show();
             break;
         case R.id.radio_button2:
             Toast.makeText(MainTabActivity.this,"button2",Toast.LENGTH_SHORT).show();
             break;
         case R.id.radio_button3:
             Toast.makeText(MainTabActivity.this,"button3",Toast.LENGTH_SHORT).show();
             break;
         case R.id.radio_button4:
             Toast.makeText(MainTabActivity.this,"button4",Toast.LENGTH_SHORT).show();
             break;
         }
     }
 }

项目下载地址:点击下载

Android之TabHost组件美化

时间: 2024-08-27 01:39:30

Android之TabHost组件美化的相关文章

Android的TabHost组件-android的学习之旅(四十)

TabHost简介 虽然,官方建议用Fagment取代TabHost,但是我们还是大概的介绍一下.TabHost是一种非常简单的组件,TabHost可以很方便的在窗口放置多个标签页,每一个标签页相当于获得了一个摆放位置. 注意 TabHost的内部需要两个组件一个是TabWidget和FrameLayout两个组件. 通话记录界面 <?xml version="1.0" encoding="utf-8"?> <TabHost xmlns:andro

12.Android之Tabhost组件学习

TabHost是整个Tab的容器,TabHost的实现有两种方式: 第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布局文件中定义就行了. 第二种方式,不继承TabActivity,在布局文件中定义TabHost即可,但是TabWidget的id必须是@android:id/tabs,FrameLayout的id必须是@android:id/tabcontent. 1)继承TabActivity 如果加载该TabH

android学习--TabHost选项卡组件

TabHost是一种非常实用的组件,TabHost可以很方便地在窗口上放置多个标签页,每个标签页获得了一个与外部容器相同大小的组件摆放区域.在手机系统的应用类似"未接电话"."已接电话"."呼出电话"等. 1 . TabHost提供了两个方法来创建选项卡.添加选项卡 newTabSpec(String tag)  : 创建选项卡 addTab(TabHost.TabSpec  tabSpec) : 添加选项卡 2.TabHost 切换选项卡触发的

Android TabHost 的美化与设计

用到的布局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" andro

转-TabHost组件(二)(实现底部菜单导航)

http://www.cnblogs.com/lichenwei/p/3975095.html 上面文章<安卓开发复习笔记——TabHost组件(一)(实现底部菜单导航)>中提到了利用自定义View(ImageView+TextView)来设置一个底部菜单的样式 这边再补充一种更为灵活的方法,可以把TabWidget隐藏,用(RadioGroup+RadioButton)来代替,并利用监听器的方式来实现监听点击点击跳转Activity. 在讲解之前,先补充几点: 1.当我们取得TabHost的

转-TabHost组件(一)(实现底部菜单导航)

http://www.cnblogs.com/lichenwei/p/3974009.html 什么是TabHost? TabHost组件的主要功能是可以进行应用程序分类管理,例如:在用户使用windows操作系统的时候,经常见到如图所示的图形界面. TabHost选项卡,说到这个组件,不得不先说一件事情,翻翻谷歌提供给我们的API,我们可以发现这样的一段话: 它告诉我们,这个组件在安卓4.0之后已经被废弃了,建议我们新的程序应该使用Fragment组件来代替它. 其实并不出乎意料,使用过Tab

Android之TabHost布局

1.概念 盛放Tab的容器就是TabHost.TabHost的实现有两种方式: 第一种继承TabActivity,从TabActivity中用getTabHost()方法获取TabHost.各个Tab中的内容在布局文件中定义就行了. 第二种方式,不继承TabActivity,在布局文件中定义TabHost即可,但是TabWidget的id必须是@android:id/tabs,FrameLayout的id必须是@android:id/tabcontent.  2.案例 1)继承TabActivi

安卓开发复习笔记——TabHost组件(实现底部菜单导航)

安卓开发复习笔记——TabHost组件(实现底部菜单导航) 4 来源:cnblog    阅读:1048   时间:2014-09-16 什么是TabHost? TabHost组件的主要功能是可以进行应用程序分类管理,例如:在用户使用windows操作系统的时候,经常见到如图所示的图形界面. TabHost选项卡,说到这个组件,不得不先说一件事情,翻翻谷歌提供给我们的API,我们可以发现这样的一段话: 它告诉我们,这个组件在安卓4.0之后已经被废弃了,建议我们新的程序应该使用Fragment组件

android开发常用组件和第三方库(二)

TimLiu-Android 自己总结的Android开源项目及库. github排名 https://github.com/trending, github搜索:https://github.com/search 目录 UI UI 卫星菜单 节选器 下拉刷新 模糊效果 HUD与Toast 进度条 UI其它 动画 网络相关 响应式编程 地图 数据库 图像浏览及处理 视频音频处理 测试及调试 动态更新热更新 消息推送 完整项目 插件 出名框架 其他 好的文章 收集android上开源的酷炫的交互动