博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Android 实现底部导航栏
阅读量:4219 次
发布时间:2019-05-26

本文共 3785 字,大约阅读时间需要 12 分钟。

Android 中的底部菜单栏,极大限度的弥补了屏幕大为我们带来的不足,现在我们可以看到各大应用都在采取这个以措施,开始的微信并没有采用该种方式但现在改版之后采用了底部导航栏,现在各大厂商出的旗舰机中大多为5.0以上的屏幕,最少也是在4.5之上,单手可操持的黄金尺寸是3.5,显然,当前手机屏幕完全违背了这一黄金原则,但是手机的大屏趋势是无法改变的,为了改变这些给人带来不方便的地方,所以我们通过各种手势和导航栏成了必不可少的。

首先要在layout中将布局写好

上述的布局是将底部的布局写好,就是通过radioButton来实现的,此处的标题也是通过自定义的。
public class MainActivity extends TabActivity {    private TabHost tabhost;    private TextView title_text;    private static boolean login=false;    @Override    protected void onCreate(Bundle savedInstanceState) {	super.onCreate(savedInstanceState);	requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);  	setContentView(R.layout.tabhost);	getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.title_icon);	title_text = (TextView) findViewById(R.id.title_text);	tabhost = MainActivity.this.getTabHost();	TabHost.TabSpec spec;	Intent intent;		intent = new Intent ().setClass(this, Eatting.class);	intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);	spec = tabhost.newTabSpec("吃饭").setIndicator("吃饭").setContent(intent);          tabhost.addTab(spec);                        intent = new Intent ().setClass(this, Feeling.class);        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        spec = tabhost.newTabSpec("心情").setIndicator("心情").setContent(intent);         tabhost.addTab(spec);                intent = new Intent ().setClass(this, MailBox.class);        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        spec = tabhost.newTabSpec("信箱").setIndicator("信箱").setContent(intent);         tabhost.addTab(spec);                intent = new Intent ().setClass(this, Shopping.class);        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        spec = tabhost.newTabSpec("购物").setIndicator("购物").setContent(intent);         tabhost.addTab(spec);                intent = new Intent ().setClass(this, Love_Pole.class);        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        spec = tabhost.newTabSpec("爱爱轴").setIndicator("爱爱轴").setContent(intent);         tabhost.addTab(spec);                tabhost.setCurrentTabByTag("爱爱轴");        title_text.setText("爱爱时间轴");        RadioGroup radioGroup=(RadioGroup) this.findViewById(R.id.main_tab_group);          radioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() {                     @Override              public void onCheckedChanged(RadioGroup group, int checkedId) {                  // TODO Auto-generated method stub                  switch (checkedId) {                  case R.id.main_tab_eatting:                      tabhost.setCurrentTabByTag("吃饭");                    title_text.setText("一起吃饭");                    break;                  case R.id.main_tab_feeling:                      tabhost.setCurrentTabByTag("心情");                    title_text.setText("晒心情");                    break;                  case R.id.main_tab_love_pole:                      tabhost.setCurrentTabByTag("爱爱轴");                    title_text.setText("爱爱时间轴");                    break;                  case R.id.main_tab_shopping:                    tabhost.setCurrentTabByTag("购物");                    title_text.setText("Let's 购");                    break;                  case R.id.main_tab_mail_box:                      tabhost.setCurrentTabByTag("信箱");                    title_text.setText("信箱");                    break;                  default:                      //tabHost.setCurrentTabByTag("我的考试");                      break;                  }              }      });    }
这样便可以实现一个简单的底部导航栏的效果。

转载地址:http://vbtmi.baihongyu.com/

你可能感兴趣的文章
gdb用法(三) 调试其他正在运行的进程
查看>>
PLSQL基础(三)游标
查看>>
PLSQL基础(四)储存过程与函数
查看>>
PLSQL基础(五)包
查看>>
oracle入门01
查看>>
java 设计模式 行为模式 -Memento(备忘录模式)
查看>>
设计模式
查看>>
单体模式Singleton
查看>>
模板方法模式
查看>>
模板方法模式实现探讨
查看>>
java适配器模式之--类适配器
查看>>
java适配器模式之二 --类适配器
查看>>
java prototype原型模型模式讲解
查看>>
【设计模式·笔记】迭代子模式
查看>>
ITERATOR 迭代子模式
查看>>
java中的泛型的一些常见例子
查看>>
设计模式---适配器模式
查看>>
设计模式---代理模式
查看>>
设计模式---单例模式
查看>>
设计模式---工厂模式
查看>>