三步搞定Android应用底部导航栏

 很多android应用底部都有一个底部导航栏,方便用户在使用过程中随意切换。目前常用的做法有三种:一种是使用自定义tabHost,一种是使用activityGroup,一种是结合FrameLayout实现。笔者再做了多款应用后,为了节约开发周期,封装了一个抽象类,只要三步便可完成底部栏的生成及不同页面的调用。

public  class ActivitycollectiondemoActivity extends ActivityCollection {
     
/**  Called when the activity  is  first created.  */
     @Override
     
public  void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);

         
// setBottomTabBackground(resId); //  设置底部导航背景图
     }

     @Override
     protected 
boolean  isShowWindowFeature() {

         return 
true ; // 设置是否显示title;
     }

     @Override
     protected List
< IndicatorInfo >  setDrawableCollections() {
         List
< IndicatorInfo >  IndicatorInfos  =   new  ArrayList < IndicatorInfo > ();
         IndicatorInfo indicatorInfo_1 
=   new  IndicatorInfo(R.drawable.baby1,
                 R.drawable.baby1_s, R.string.baby1, 
12 , Color.WHITE,
                 
new  Intent(ActivitycollectiondemoActivity.this,
                         Activity01.class));
         IndicatorInfo indicatorInfo_2 
=   new  IndicatorInfo(R.drawable.baby2,
                 R.drawable.baby2_s, R.string.baby2, 
12 , Color.WHITE,
                 
new  Intent(ActivitycollectiondemoActivity.this,
                         Activity02.class));
         IndicatorInfo indicatorInfo_3 
=   new  IndicatorInfo(R.drawable.baby3,
                 R.drawable.baby3_s, R.string.baby3, 
12 , Color.WHITE,
                 
new  Intent(ActivitycollectiondemoActivity.this,
                         Activity03.class));
         IndicatorInfo indicatorInfo_4 
=   new  IndicatorInfo(R.drawable.baby4,
                 R.drawable.baby4_s, R.string.baby4, 
12 , Color.WHITE,
                 
new  Intent(ActivitycollectiondemoActivity.this,
                         Activity04.class));
         IndicatorInfos.add(indicatorInfo_1);
         IndicatorInfos.add(indicatorInfo_2);
         IndicatorInfos.add(indicatorInfo_3);
         IndicatorInfos.add(indicatorInfo_4);

         return IndicatorInfos;
     }

  第一步:导入jar包

  第二步:让你的homeactivity 继承ActivityCollection类

  第三步:将你的图片资源及跳转intent放入list中,设置可选项

  Ok,一个含有底部导航栏的应用雏形就出来了,对付一般的应用足够,你可以腾出更多的时间考虑业务逻辑。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值