简体   繁体   中英

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.

A screenshot of the current navigation bar is below (I marked the navigation bars in red for this SO question):

在此处输入图片说明

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)

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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