本文共 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/