Android ActionBar.Tab setCustomView() doesn't fill_parent

后端 未结 4 1604
难免孤独
难免孤独 2020-12-10 15:22

I\'m using ActionBar.Tab setCustomView() method with this layout:




        
相关标签:
4条回答
  • 2020-12-10 15:41

    To every created tab object just add layoutParams:

    ..    
    tab.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
    actionBar.addTab(tab);
    
    0 讨论(0)
  • 2020-12-10 15:44

    You have to rely on android:margin and android:padding when dealing with actionbarcompat's setCustomView

    keeping in mind that it seems like the root element's padding, width, height, and margin, gets ignored.

    0 讨论(0)
  • 2020-12-10 15:44

    If you're still having the issue, I found a way to get the whole space : ActionBar Tab with custom View not centered

    0 讨论(0)
  • 2020-12-10 15:51

    Just ran into this myself and figured out the solution. You should create a style for the tabview that clears the background and the padding and use it in your theme.

    styles.xml:

    <style name="Custom.ActionBar.TabView.Empty" parent="@style/Widget.AppCompat.ActionBar.TabView">
        <item name="android:background">@null</item>
        <item name="android:padding">0dp</item>
    </style>
    

    themes.xml:

    <style name="Theme.Custom" parent="@style/Theme.AppCompat.Light">
        <item name="android:actionBarTabStyle">@style/Custom.ActionBar.TabView.Empty</item>
        <item name="actionBarTabStyle">@style/Custom.ActionBar.TabView.Empty</item>
    </style>
    
    0 讨论(0)
提交回复
热议问题