http://www.cnblogs.com/superbearman/archive/2011/12/14/superbearman6.html
很多android应用底部都有一个底部导航栏,方便用户在使用过程中随意切换。目前常用的做法有三种:一种是使用自定义tabHost,一种是使用activityGroup,一种是结合FrameLayout实现。笔者再做了多款应用后,为了节约开发周期,封装了一个抽象类,只要三步便可完成底部栏的生成及不同页面的调用。
1 public class ActivitycollectiondemoActivity extends ActivityCollection { 2 /** Called when the activity is first created. */ 3 @Override 4 public void onCreate(Bundle savedInstanceState) { 5 super.onCreate(savedInstanceState); 6 7 //setBottomTabBackground(resId);// 设置底部导航背景图 8 } 9 10 @Override 11 protected boolean isShowWindowFeature() { 12 13 return true;//设置是否显示title; 14 } 15 16 @Override 17 protected List<IndicatorInfo> setDrawableCollections() { 18 List<IndicatorInfo> IndicatorInfos = new ArrayList<IndicatorInfo>(); 19 IndicatorInfo indicatorInfo_1 = new IndicatorInfo(R.drawable.baby1, 20 R.drawable.baby1_s, R.string.baby1, 12, Color.WHITE, 21 new Intent(ActivitycollectiondemoActivity.this, 22 Activity01.class)); 23 IndicatorInfo indicatorInfo_2 = new IndicatorInfo(R.drawable.baby2, 24 R.drawable.baby2_s, R.string.baby2, 12, Color.WHITE, 25 new Intent(ActivitycollectiondemoActivity.this, 26 Activity02.class)); 27 IndicatorInfo indicatorInfo_3 = new IndicatorInfo(R.drawable.baby3, 28 R.drawable.baby3_s, R.string.baby3, 12, Color.WHITE, 29 new Intent(ActivitycollectiondemoActivity.this, 30 Activity03.class)); 31 IndicatorInfo indicatorInfo_4 = new IndicatorInfo(R.drawable.baby4, 32 R.drawable.baby4_s, R.string.baby4, 12, Color.WHITE, 33 new Intent(ActivitycollectiondemoActivity.this, 34 Activity04.class)); 35 IndicatorInfos.add(indicatorInfo_1); 36 IndicatorInfos.add(indicatorInfo_2); 37 IndicatorInfos.add(indicatorInfo_3); 38 IndicatorInfos.add(indicatorInfo_4); 39 40 return IndicatorInfos; 41 }
第一步:导入jar包
第二步:让你的homeactivity 继承ActivityCollection类
第三步:将你的图片资源及跳转intent放入list<IndicatorInfo>中,设置可选项
Ok,一个含有底部导航栏的应用雏形就出来了,对付一般的应用足够,你可以腾出更多的时间考虑业务逻辑。
jar包及demo请参见:jar包及demo