自定义底部tab
public class MainActivity extends TabActivity implements
OnCheckedChangeListener {
private RadioGroup mainTab;
private TabHost tabhost;
private Intent iHome;
private Intent iNews;
private Intent iInfo;
private RadioButton radio_button1,radio_button0,radio_button2;
private String value=null; @Override
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);
setContentView(R.layout.tab);
value=getIntent().getStringExtra("value");
mainTab = (RadioGroup) findViewById(R.id.main_tab);
radio_button1=(RadioButton)findViewById(R.id.radio_button1);
radio_button0=(RadioButton)findViewById(R.id.radio_button0);
radio_button2=(RadioButton)findViewById(R.id.radio_button2);
mainTab.setOnCheckedChangeListener(this);
tabhost = getTabHost();
init(); } @SuppressLint("NewApi")
@Override
public void onCheckedChanged(RadioGroup group, int checkedId) {
switch (checkedId) {
case R.id.radio_button0: //账单
tabhost.setCurrentTab(0);
Drawable drawable1=this.getResources().getDrawable(R.drawable.oneo);
radio_button0.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable1,null,null);
Drawable drawable11=this.getResources().getDrawable(R.drawable.aaa);
radio_button1.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable11,null,null);
Drawable drawable111=this.getResources().getDrawable(R.drawable.cccc);
radio_button2.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable111,null,null);
break;
case R.id.radio_button1://信息
tabhost.setCurrentTab(1);
Drawable drawable0=this.getResources().getDrawable(R.drawable.two);
radio_button1.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable0,null,null);
Drawable drawable00=this.getResources().getDrawable(R.drawable.bbb);
radio_button0.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable00,null,null); Drawable drawable000=this.getResources().getDrawable(R.drawable.cccc);
radio_button2.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable000,null,null); break;
case R.id.radio_button2://彩神岛
tabhost.setCurrentTab(2);
Drawable drawable2=this.getResources().getDrawable(R.drawable.threet);
radio_button2.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable2,null,null);
Drawable drawable22=this.getResources().getDrawable(R.drawable.aaa);
radio_button1.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable22,null,null);
Drawable drawable333=this.getResources().getDrawable(R.drawable.bbb);
radio_button0.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable333,null,null); break; } } @SuppressLint("NewApi")
public void init() {
//初始化点击图标,跳转的接口
iNews = new Intent(this, BillActivity.class);
iNews.putExtra("value", "1");
tabhost.addTab(tabhost
.newTabSpec("iNews")
.setIndicator(getResources().getString(R.string.main_bill),
getResources().getDrawable(R.drawable.bbb))
.setContent(iNews));
iHome = new Intent(this, MessageActivity.class);
iHome.putExtra("value", "1");
tabhost.addTab(tabhost
.newTabSpec("iHome")
.setIndicator(getResources().getString(R.string.main_msg),
getResources().getDrawable(R.drawable.aaa))
.setContent(iHome));
iInfo = new Intent(this, SettingActivity.class);
iInfo.putExtra("value", "1");
tabhost.addTab(tabhost
.newTabSpec("iInfo")
.setIndicator(getResources().getString(R.string.main_setting),
getResources().getDrawable(R.drawable.cccc))
.setContent(iInfo));
Log.v("tag", "value:"+value);
if(value.equals("")||value.equals(null)||value.equals("1")){
tabhost.setCurrentTab(0);
} if(value.equals("2set")){
tabhost.setCurrentTab(2);
Drawable drawable2=this.getResources().getDrawable(R.drawable.threet);
radio_button2.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable2,null,null);
Drawable drawable22=this.getResources().getDrawable(R.drawable.aaa);
radio_button1.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable22,null,null);
Drawable drawable333=this.getResources().getDrawable(R.drawable.bbb);
radio_button0.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable333,null,null);
}if(value.equals("2msg")){
tabhost.setCurrentTab(1);
Drawable drawable0=this.getResources().getDrawable(R.drawable.two);
radio_button1.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable0,null,null);
Drawable drawable00=this.getResources().getDrawable(R.drawable.bbb);
radio_button0.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable00,null,null);
Drawable drawable000=this.getResources().getDrawable(R.drawable.cccc);
radio_button2.setCompoundDrawablesRelativeWithIntrinsicBounds(null,drawable000,null,null); }
}
xml中:
<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="@color/white" > <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" /> <TextView
android:id="@+id/line"
android:layout_width="fill_parent"
android:layout_height="1px"
android:background="@color/black" /> <RadioGroup
android:id="@+id/main_tab"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="@color/white"
android:gravity="center_vertical"
android:orientation="horizontal" > <RadioButton
android:id="@+id/radio_button0"
style="@style/main_tab_bottom"
android:layout_marginTop="0.0dip"
android:drawableTop="@drawable/oneo"
android:text="@string/main_bill" /> <RadioButton
android:id="@+id/radio_button1"
style="@style/main_tab_bottom"
android:layout_marginTop="0.0dip"
android:drawableTop="@drawable/aaa"
android:text="@string/main_msg" /> <RadioButton
android:id="@+id/radio_button2"
style="@style/main_tab_bottom"
android:layout_marginTop="0.0dip"
android:drawableTop="@drawable/cccc"
android:text="@string/main_setting" />
</RadioGroup>
</LinearLayout> </TabHost>
xml中的style:
<style name="main_tab_bottom">
<item name="android:textSize">@dimen/bottom_tab_font_size</item>
<item name="android:textColor">@color/black</item>
<item name="android:ellipsize">marquee</item>
<item name="android:gravity">center_horizontal</item>
<item name="android:background">@color/white</item>
<item name="android:paddingTop">@dimen/bottom_tab_padding_up</item>
<item name="android:paddingBottom">@dimen/bottom_tab_padding_up</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">@dimen/bottom_tab_padding_drawable</item>
<item name="android:layout_weight">1.0</item>
</style>
效果如下:

自定义底部tab的更多相关文章
- 小程序自定义底部tab
首页wxml的代码: <view class="nav" hover-class="none"> <view class="inde ...
- tab 切换 和 BottomNavigationBar 自定义 底部导航条
BottomNavigationBar 组件 BottomNavigationBar 是底部导航条,可以让我们定义底部 Tab 切换,bottomNavigationBar是 Scaffold ...
- 自定义 简单 底部tab
项目地址:https://gitee.com/jielov/music-netease-api.git 先创建三个页面 分别为 home.vue , classify.vue, my.vue . 以下 ...
- TabBottomFragmentLayout【自定义底部选项卡区域(搭配Fragment)】
版权声明:本文为HaiyuKing原创文章,转载请注明出处! 前言 自定义底部选项卡布局LinearLayout类,然后配合Fragment,实现切换Fragment功能. 缺点: 1.底部选项卡区域 ...
- 15 Flutter BottomNavigationBar自定义底部导航条 以及实现页面切换 以及模块化
效果: /** * Flutter BottomNavigationBar 自定义底部导航条.以及实现页面切换: * BottomNavigationBar是底部导航条,可以让我们定义底部Tab ...
- Android自定义控件----RadioGroup实现APP首页底部Tab的切换
[声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/ ...
- 自定义底部工具栏及顶部工具栏和Fragment配合使用demo
首先简单的介绍下fragment,fragment是android3.0新增的概念,其中文意思是碎片,它与activity非常相似,用来在一个activity中描述一些行为或一部分用户界面.使用锁个f ...
- 界面底部Tab实现
现在基本上大部分的手机APP都要实现底部Tab,底部实现Tab的实现方式有很多种,那么有没有好的实现方式呢? 今天我将使用一个开源插件来实现底部Tab 参考自zhangli_的博客:http://bl ...
- Android自定义底部带有动画的Dialog
Android自定义底部带有动画的Dialog 效果图 先看效果图,是不是你想要的呢 自定义Dialog package --.view; import android.app.Dialog; imp ...
随机推荐
- ES6 - for...of
for...of是一种用来遍历数据结构的方法,可遍历的对象包括:数组,对象,字符串,节点数组等 我们先来看一下现在存在的遍历方式: var arr=[1,2,3,4] (1)for循环 缺点:代码不够 ...
- C语言编译和链接过程
1.程序的编译 一般而言,大多数编译系统都提供编译驱动程序(complier driver),根据用户需求调用语言预处理器,编译器,汇编器和链接器.例如有如下历程://main.c void swa ...
- MongoDB丢数据问题的分析
坊间有很多传说MongoDB会丢数据.特别是最近有一个InfoQ翻译的Sven的一篇水文(为什么叫做水文?因为里面并没有他自己的原创,只是搜罗了一些网上的博客,炒了些冷饭吃),其中又提到了丢数据的事情 ...
- 【SVN】自动备份SVN仓库
仓库的位置为:C:\xxx\SVNRepo\ MyCommonUtils MyStudyProject SVN仓库备份.bat '参考连接:http://www.uml.org.cn/pzgl/201 ...
- javascript性能优化总结一(转载人家)
一直在学习javascript,也有看过<犀利开发Jquery内核详解与实践>,对这本书的评价只有两个字犀利,可能是对javascript理解的还不够透彻异或是自己太笨,更多的是自己不擅于 ...
- [系统集成] OpenLDAP使用AD密码
关于OpenLDAP和AD帐号的整合,网上有大量的文档,绝大多数都不符合我们的需求,下面的方案是我经过调研.测试.修改.最终采用的. . 需求概述 公司网络中有两种帐号:OpenLDAP帐号和AD帐号 ...
- Provisional, Temporary 和Interim 的区别
1 Provisional adj. 临时的.暂时的.暂定的:n. 临时邮票 强调在一定时期内暂时的.双方同意的但还不是最终确定的决定或者条约等. Such as例如: Provisional go ...
- .NET:序列化和反序列化
.NET:序列化和反序列化 需要反序列化的字符串: { "LouPanID": "sample string 1", "LouPanHao" ...
- 用wamp配置的环境,想用CMD连接mysql怎么连
签:用wamp配置的环境 想用cmd连接mysql怎么连 进到d盘该目录 (cd切不了盘,就输入盘符加冒号回车,再cd到目录) WAMP装好后,mysql数据库运行时没有 mysql 和 ...
- SQL中ISNULL用法示例
ISNULLSQL查询示例SELECT ISNULL 使用指定的替换值替换 NULL. 语法 :ISNULL ( check_expression , replacement_val ...