Android - customizing actionbar sherlock tabs

后端 未结 2 2075
半阙折子戏
半阙折子戏 2020-12-14 03:50

Im trying to customize the actionbar sherlock tabs so they display the tab text below the tab icon. After searching and reading about the subject, I\'m still not having much

相关标签:
2条回答
  • 2020-12-14 04:02

    I don't know if you have found an answer for this or not yet but one solution could be to modify the tab image to include the text, with GIMP or photoshop something, and then just set those images in the tabs, instead of images and text. It is a bit of an awkward way of doing it but it would work.

    Hope this helps!

    0 讨论(0)
  • 2020-12-14 04:12

    I have solved that by using a compound drawable:

    tv = new TextView(this);
    tv.setText(R.string.tab_movies);
    tv.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.nav_movies, 0, 0);
    
    mBar.addTab(mBar
        .newTab()
        .setCustomView(tv)
        .setTabListener(
        new TabListenerImpl<TheatersTabActivity>(this, "theaters",
            TheatersTabActivity.class)));
    

    In order to deal with the selected or not selected image, I am using a selector:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android" >
        <item 
            android:state_selected="true"
            android:drawable="@drawable/nav_movies_on"/>
        <item 
            android:state_selected="false"
            android:drawable="@drawable/nav_movies_off"/>
    </selector>
    
    0 讨论(0)
提交回复
热议问题