展会信息港展会大全

android底部菜单栏
来源:互联网   发布日期:2015-10-03 13:18:34   浏览:2020次  

导读:android程序,许多时候需要菜单栏显示在底部或顶部,但是没有很好的组建供程序员调用,过自定义了一个视图,用来实现底部菜单栏,效果如下图:实现的主要代码:01@Override02 public void onCreate(Bundle s......

android程序,许多时候需要菜单栏显示在底部或顶部,但是没有很好的组建供程序员调用,过自定义了一个视图,用来实现底部菜单栏,效果如下图:

实现的主要代码:

01@Override

02 public void onCreate(Bundle savedInstanceState) {

03 super.onCreate(savedInstanceState);

04 requestWindowFeature(Window.FEATURE_NO_TITLE);

05 setContentView(R.layout.main); linearLayout = (LinearLayout) findViewById(R.id.home);

06 linearLayout.setOnClickListener(new OnClickListener() {

07 @Override

08 public void onClick(View v) {

09 linearLayout

10 .setBackgroundResource(R.drawable.tab_two_highlight);

11 publish.setBackgroundResource(R.drawable.tab_one_normal);

12 change.setBackgroundResource(R.drawable.tab_one_normal);

13 more.setBackgroundResource(R.drawable.tab_one_normal);

14 }

15 });

16 linearLayout

17 .setBackgroundResource(R.drawable.tab_two_highlight); publish = (LinearLayout) findViewById(R.id.publish);

18 publish.setOnClickListener(new OnClickListener() {

19 @Override

20 public void onClick(View v) {

21 publish.setBackgroundResource(R.drawable.tab_two_highlight);

22 linearLayout.setBackgroundResource(R.drawable.tab_one_normal);

23 change.setBackgroundResource(R.drawable.tab_one_normal);

24 more.setBackgroundResource(R.drawable.tab_one_normal);

25 }

26 }); change = (LinearLayout) findViewById(R.id.change);

27 change.setOnClickListener(new OnClickListener() {

28 @Override

29 public void onClick(View v) {

30 change.setBackgroundResource(R.drawable.tab_two_highlight);

31 linearLayout.setBackgroundResource(R.drawable.tab_one_normal);

32 publish.setBackgroundResource(R.drawable.tab_one_normal);

33 more.setBackgroundResource(R.drawable.tab_one_normal);

34 }

35 }); more = (LinearLayout) findViewById(R.id.more);

36 more.setOnClickListener(new OnClickListener() {

37 @Override

38 public void onClick(View v) {

39 more.setBackgroundResource(R.drawable.tab_two_highlight);

40 linearLayout.setBackgroundResource(R.drawable.tab_one_normal);

41 publish.setBackgroundResource(R.drawable.tab_one_normal);

42 change.setBackgroundResource(R.drawable.tab_one_normal);

43 }

44 });

45 }

配置文件实现:

01

02

03 android:orientation= horizontalandroid:layout_width= fill_parent

04 android:layout_height= wrap_content >

05

06 android:orientation= verticalandroid:layout_width= 80px

07 android:layout_height= wrap_contentandroid:id= @+id/home

08 android:background= @drawable/tab_one_normal >

09

10 android:layout_height= wrap_contentandroid:text= @string/home

11 android:gravity= centerandroid:paddingTop= 29px

12 android:background= @drawable/home/>

13

14

15 android:layout_height= wrap_contentandroid:src= @drawable/line/>

16

17 android:orientation= verticalandroid:layout_width= 80px

18 android:layout_height= wrap_contentandroid:background= @drawable/tab_one_normal

19 android:id= @+id/publish >

20

21 android:layout_height= wrap_contentandroid:text= @string/publish

22 android:gravity= centerandroid:paddingTop= 29px

23 android:background= @drawable/publish/>

24

25

26 android:layout_height= wrap_contentandroid:src= @drawable/line/>

27

28 android:orientation= verticalandroid:layout_width= 80pxandroid:id= @+id/change

29 android:layout_height= wrap_contentandroid:background= @drawable/tab_one_normal >

30

31 android:layout_height= wrap_contentandroid:text= @string/change

32 android:gravity= centerandroid:paddingTop= 29px

33 android:background= @drawable/change/>

34

35

36 android:layout_height= wrap_contentandroid:src= @drawable/line/>

37

38 android:orientation= verticalandroid:layout_width= 80pxandroid:id= @+id/more

39 android:layout_height= wrap_contentandroid:background= @drawable/tab_one_normal >

40

41 android:layout_height= wrap_contentandroid:text= @string/more

42 android:gravity= centerandroid:paddingTop= 29px

43 android:background= @drawable/more/>

44

45

46源代码见:http://easymorse.googlecode.com/svn/trunk/android.bottom

赞助本站

人工智能实验室

相关热词: 底部菜单

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港