自定义底部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 ...
随机推荐
- 7个你可能不认识的CSS单位:rem vh vw vmin vmax ex ch
rem 我们首先介绍下和我们熟悉的很相似的货.em 被定义为相对于当前对象内文本的字体大小.炒个栗子,如果你给body小哥设置了font-size字体大小,那么body小哥的任何子元素的1em就是等于 ...
- C语言实现简单线程池(转-Newerth)
有时我们会需要大量线程来处理一些相互独立的任务,为了避免频繁的申请释放线程所带来的开销,我们可以使用线程池.下面是一个C语言实现的简单的线程池. 头文件: 1: #ifndef THREAD_POOL ...
- locate无法open mlocate.db
# locate xxxx locate: can not open () `/var/lib/mlocate/mlocate.db': No such file or directory 如果出现此 ...
- shell问题(转)
一个同学问我一个问题,说有以下文件内容,要求输出为特定的格式.这里就献丑给出一个处理的方法吧,由于时间关系可能我的答案并不是最好的,但是我尽量将我的答案讲解明白,让你理解处理的方法.如果您有简单明了的 ...
- Alpha版本——Postmortem会议
No Bug 031402401鲍亮 031402402曹鑫杰 031402403常松 031402412林淋 031402418汪培侨 031402426许秋鑫 设想和目标 1.我们的软件要解决什么 ...
- PHP 输出图像 imagegif 、imagejpeg 与 imagepng 函数
imagegif().imagejpeg().imagepng() 和 imagewbmp() 函数分别允许以 GIF.JPEG.PNG 和 WBMP 格式将图像输出到浏览器或文件. PHP 输出图像 ...
- Android Gradle 多Module单独编译一个Module
假如项目中有两个Module,app1和app2.假如我只想对app1 module进行build,则可以: gradle :App1:build build命令可以换成任意gradle命令.
- eclipse下tomcat插件配置说明
- C# Dictionary 的几种遍历方法
Dictionary<string, int> list = new Dictionary<string, int>(); list.Add("d", 1) ...
- [HTML] CSS Id 和 Class选择器
id 和 class 选择器 如果你要在HTML元素中设置CSS样式,你需要在元素中设置"id" 和 "class"选择器. id 选择器 id 选择器可以为标 ...