养殖 - 种植 - 加工 - 创业 - 骗局 - 问答 - 百科 - 节气 - 民俗 - 手机版
您的当前位置: 致富创业网 > 致富项目 > 问答 > [三步搞定android应用底部导航栏]

[三步搞定android应用底部导航栏]

来源:问答 时间:2018-08-16 点击:

很多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 setDrawableCollections() {

List IndicatorInfos = new ArrayList();

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

推荐访问:三步 搞定 导航 三步搞定android应用底部导航栏 五步搞定android android底部导航菜单

致富创业网 www.csyzzm.com

Copyright © 2002-2018 . 致富创业网 版权所有 湘ICP备12008529号-1

Top