慕无忌1623718
很多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 ListIndicatorInfo> setDrawableCollections() { ListIndicatorInfo> IndicatorInfos = new ArrayListIndicatorInfo>(); 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中,设置可选项;雏形就形成啦!