Customizing ActionBar Tabs on Android 4

后端 未结 7 1662
甜味超标
甜味超标 2021-01-01 19:26

I\'m trying to customize Tabs on my ActionBar. I just want to align tabs to phone screen and make it stretchable for various screens. But all I get is this:

相关标签:
7条回答
  • 2021-01-01 20:03

    You can use the setCustomView method.

    0 讨论(0)
  • 2021-01-01 20:04

    I have found using style guides for the tabs to very inconsistent for honeycomb, It was much easier to just inflate a custom view that does want you want.

    Fragment serivceFrag = new ServicesFragment();
    Tab serviceTab = bar.newTab();
    TextViewPlus serviceTabTextView =(TextViewPlus)getLayoutInflater().inflate(R.layout.tab_item_layout, null);
    serviceTabTextView.setText(servicesLabel);
    serviceTab.setCustomView(serviceTabTextView);
    serviceTab.setTabListener(new TabListenerFragment(serivceFrag,"Service",R.id.MainInfoPaneFragment));
    bar.addTab(serviceTab);
    

    This to me was much simpler,

    0 讨论(0)
  • 2021-01-01 20:04

    Change to:

    <style name="MyActionBarTabTextStyle" parent="@android:style/Widget.Holo.ActionBar.TabText">
         <item name="android:textSize">14dip</item>
         <item name="android:padding">0dip</item>
    </style>
    
    0 讨论(0)
  • 2021-01-01 20:08

    I strongly recommend that you use ViewPagerExtensions library, it give you 5 different styled tabs to you choose from, also the problem that you have to fill tabs in portrait and landscape ,ode for each screen size is already solved in this library.

    By the way, if you look inside the library´s code, you can easy theme this yourself.

    Also, if you have trouble implementing this with fragment page, look actionbarsherlock-tabs-multi-fragments

    0 讨论(0)
  • 2021-01-01 20:10

    There's a brand new tool to generate the correct 9patch images for the actionbar : http://jgilfelt.github.com/android-actionbarstylegenerator/

    0 讨论(0)
  • 2021-01-01 20:24

    I think you're inheriting from the wrong style, try:

    <style name="MyActionBarTabTextStyle" parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
        <item name="android:textSize">14sp</item>
        <item name="android:padding">0dip</item>
    </style>
    

    EDIT: also, make sure you use sp instead of dip for font size (14sp)

    0 讨论(0)
提交回复
热议问题