自定义底部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 ...
随机推荐
- JS几种table切换
1.使用className <!doctype html> <html lang="en"> <head> <meta charset=& ...
- VendorNPC.lua --随身商人
print(">>Script: More Vendor NPC.") local NPCNAME="随身商人" --GOSSIP_ICON 菜单图 ...
- 在CentOS_RHEL 6上安装Metasploit的框架
https://github.com/rapid7/metasploit-framework/wiki/Nightly-Installers 1. shyum update curl https:// ...
- 知识积累:CGI,FastCGI,PHP-CGI与PHP-FPM
CGICGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,其程序须运行在网络服务器上.CGI可以用任何一种语 ...
- [solr] - 数据库导入
这里使用的是mysql测试. 1.先在mysql中建一个表:solr_test 2.插入几条测试数据: 3.用记事本打solrconfig.xml文件,在solrhome文件夹中.E:\solrhom ...
- ruby md5加签验签方法
# md5签名def md5_sign(data,key) return OpenSSL::Digest::MD5.hexdigest(data+key)end # md5验签def md5_veri ...
- 黄聪:基于jQuery+JSON的省市区三级地区联动
查看演示:http://www.helloweba.com/demo/cityselect/ 源码下载:http://files.cnblogs.com/files/huangcong/citysel ...
- 【原】CSS3的3D动画 ——3D旋转之骰子样式的钟表(2)下.md
之前看到智能社主页的那个骰子样式的钟表,最近研究了一下,虽然没有仔细看他是怎么做的,但是学了css3的动画之后想自己尝试着写一下,用到的原理可能和智能社网站的不太一样,我自己主要用到了css3和js. ...
- Visual Studio Enterprise 2015下载 Update3
Visual Studio 2015 是一个丰富的集成开发环境,可用于创建出色的 Windows.Android 和 iOS 应用程序以及新式 Web 应用程序和云服务. 1.适用于各种规模和复杂程度 ...
- 45. Scramble String
Scramble String Given a string s1, we may represent it as a binary tree by partitioning it to two no ...