自定义底部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 ...
随机推荐
- iframe的使用
function Report() { var info = document.getElementById("iframeReport"); ...
- Java多线程之ConcurrentSkipListMap深入分析(转)
Java多线程之ConcurrentSkipListMap深入分析 一.前言 concurrentHashMap与ConcurrentSkipListMap性能测试 在4线程1.6万数据的条件下, ...
- pcl点云文件格式
PCD版本 在点云库(PCL)1.0版本发布之前,PCD文件格式有不同的修订号.这些修订号用PCD_Vx来编号(例如,PCD_V5.PCD_V6.PCD_V7等等),代表PCD文件的0.x版本号.然而 ...
- LEETCODE —— binary tree [Same Tree] && [Maximum Depth of Binary Tree]
Same Tree Given two binary trees, write a function to check if they are equal or not. Two binary tre ...
- kuangbin_SegTree A (HDU 1166)
大牛们的文章里这句 题意:O(-1) 思路:O(-1) 深深地嘲讽了我........ 不过单点更新 区间求和也算是基本操作了吧 (虽然我还是看了好久才理解) 跟之前学图论的时候感觉完全不一样啊orz ...
- repeater没有数据显示暂无数据,无记录
方法就是在FooterTemplate加个Label并根据repeater.Items.Count判断是否有记录.关键代码如下: <FooterTemplate> <asp:Labe ...
- POJ-2726-Holiday Hotel
Holiday Hotel Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8302 Accepted: 3249 D ...
- ORA-12154: TNS:could not resolve the connect identifier specified
场景: .Net程序无法连接到数据库 现象: 2015/8/26 11:02:03 ORA-12154: TNS:could not resolve the connect identifier sp ...
- linux 下 文件权限和文件主
文件与文件夹的权限和所有者 1.chmod -R 755 file 777 含义与来源: 777含义:分别为:所有者.同组用户.其他用户 7的来源:文件有三种操作模式:读4.写2.执行1,分别值为42 ...
- HBase体系结构(转)
HBase的服务器体系结构遵循简单的主从服务器架构,它由HRegion服务器(HRegion Server)群和HBase Master服务器(HBase Master Server)构成.HBase ...