简体   繁体   English

在Android操作栏中自定义导航标签

[英]Customize Navigation Tabs in Android Action bar

I have an Android app that Im making now using one of the default templates: I believe it was Fixed Tabs + Swipe. 我有一个我正在使用默认模板之一制作的Android应用程序:我相信它是“固定选项卡+滑动”。

A screenshot of the current navigation bar is below (I marked the navigation bars in red for this SO question): 下面是当前导航栏的屏幕截图(此SO问题我用红色标记了导航栏):

在此处输入图片说明

My question is, is it possible to customize these navigation tabs? 我的问题是,是否可以自定义这些导航选项卡? I would like to increase their height and also add an icon ideally on top of the text. 我想增加它们的高度,并在文本上方理想地添加一个图标。 Also, Id like to change the colors. 另外,我想更改颜色。

Something like below: 如下所示:

|           |          |            |
|  icon     |  icon    |   icon     |
|           |          |            |
|           |          |            |
|  HOME     |   NEW    |  FAVORITE  |

I can't find any clear documentation that states that this type of navigation tabbar can be customized. 我找不到任何明确的文档说明这种类型的导航选项卡可以自定义。 Is this pretty much set as is? 这是设置好了吗?

Thank you! 谢谢!

Try the code below to add icons to Actionbar tabs 尝试下面的代码向“操作栏”标签添加图标

    ActionBar bar = getSupportActionBar();
    bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);

    ActionBar.Tab tab1 = bar.newTab();
    ActionBar.Tab tab2 = bar.newTab();
    ActionBar.Tab tab3 = bar.newTab();

    tab1.setIcon(R.drawable.homeicon);

    tab2.setIcon(R.drawable.newicon);

    tab3.setIcon(R.drawable.favicon);

And use icons like below (text should be bottom of image) 并使用如下所示的图标(文本应在图像的底部)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM