Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove actionbar tabs padding in Android

Tags:

http://imageshack.us/photo/my-images/4/iy47.jpg/

I have a problem with action bar tabs, I would like to remove the padding left or right in tabs.

I tried this style, but it didn't work :

<!-- indicator tab color -->
<style name="ActionBarTabBarStyle" parent="@style/Widget.AppCompat.ActionBar.TabView">
   <item name="android:background">@drawable/tab_indicator_ab_example</item>
   <item name="android:paddingLeft">0dp</item>
   <item name="android:paddingRight">0dp</item>
</style>

Do you have any idea?

like image 556
rompotier Avatar asked Aug 06 '13 11:08

rompotier


3 Answers

You can achieve the look your looking for by configuring the 'Widget.Sherlock.Light.ActionBar.Solid.Inverse'. Specifically padding and minWidth on the TabView and the backgroundStacked.

<style name="GPA_Sherlock_theme" parent="@style/Theme.Sherlock.Light.DarkActionBar">        
    <item name="android:actionBarStyle">@style/ActionBar.Solid.Example</item> 
    <item name="android:actionBarTabStyle">@style/ActionBarTabStyle.Example</item>
    <item name="actionBarStyle">@style/ActionBar.Solid.Example</item> 
    <item name="actionBarTabStyle">@style/ActionBarTabStyle.Example</item>
</style>

 <style name="ActionBarTabStyle.Example" parent="@style/Widget.Sherlock.ActionBar.TabView">
     <item name="android:paddingLeft">0dp</item>        
     <item name="android:paddingRight">0dp</item>     
     <item name="android:minWidth">0dp</item> 
</style>

<style name="ActionBar.Solid.Example" parent="@style/Widget.Sherlock.Light.ActionBar.Solid.Inverse"> 
     <item name="android:backgroundStacked">@drawable/ab_stacked_solid_example</item> 
     <item name="backgroundStacked">@drawable/ab_stacked_solid_example</item> 
</style> 
like image 184
Randolph Avatar answered Sep 27 '22 15:09

Randolph


Add app:tabPaddingStart="0dp" and app:tabPaddingEnd="0dp" to TabLayout. It works for me.

<android.support.design.widget.TabLayout
     android:id="@+id/tabs"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     app:tabGravity="fill"
     app:tabPaddingStart="0dp"
     app:tabPaddingEnd="0dp"
     app:tabIndicatorColor="#FF0000"
     app:tabMode="fixed" />

and add xmlns:app="http://schemas.android.com/apk/res-auto" to parent layout

like image 3
Arun Avatar answered Sep 26 '22 15:09

Arun


You can use custom layout..

    ActionBar actionBar;
    actionBar = getActivity().getActionBar();
    actionBar.setCustomView(R.layout.your_layout);
like image 1
ifaim Avatar answered Sep 28 '22 15:09

ifaim