Android Tab platform doesn't take full width with custom view

Android TabLayout tabPaddingTop and tabPaddingBottom not removed

Please refer to the above problem.

Even after I updated my design library to "23.2.0", the tab layout is all messed up.

Below is a tab layout.

Xml Part: -

<android.support.design.widget.TabLayout android:id="@+id/sliding_tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabIndicatorColor="@android:color/white" app:tabIndicatorHeight="@dimen/dp2" app:tabMode="fixed" app:tabSelectedTextColor="@android:color/white" app:tabTextAppearance="@style/MyCustomTabTextAppearance" /> 

xml styles: -

 <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/color_156084</item> </style> <style name="MyCustomTabTextAppearance" parent="TextAppearance.Design.Tab"> <item name="android:textSize">@dimen/sp14</item> <item name="android:textColor">@android:color/white</item> <item name="textAllCaps">false</item> </style> 

I installed the addon to -1dp and even made tabGravity to populate, but nothing works.

This code was used to work in earlier versions, but now, if I lower it, I get the def class definition error on TintManager.

enter image description here

+6
source share
5 answers

Setting various values โ€‹โ€‹or layout options did not work, so the only solution I got was to add the following after adding tabs to the tab layout,

 final ViewGroup test = (ViewGroup)(tabs.getChildAt(0));//tabs is your Tablayout int tabLen = test.getChildCount(); for (int i = 0; i < tabLen; i++) { View v = test.getChildAt(i); v.setPadding(0, 0, 0, 0); } 
+7
source

Try adding the following attributes to TabLayout:

 app:tabPaddingStart="-1dp" app:tabPaddingEnd="-1dp" 

Hope it works.

+1
source

Try adding TabLayout to LinearLayout, for example:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical"> <android.support.design.widget.TabLayout android:id="@+id/sliding_tabs" style="@style/MyCustomTabLayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#FFF" /> </LinearLayout> 

In Styles.xml add:

  <style name="MyCustomTabLayout" parent="Widget.Design.TabLayout"> <item name="tabTextAppearance">@style/MyCustomTextAppearance</item> </style> <style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab"> <item name="textAllCaps">false</item> </style> 
0
source

Just pass your tabLayout to this method and you're done!

 private void setTabLayoutMatchParent(TabLayout tabLayout) { final ViewGroup tabLayoutChild = (ViewGroup)(tabLayout.getChildAt(0)); int tabLen = tabLayoutChild.getChildCount(); for (int j = 0; j < tabLen; j++) { View v = tabLayoutChild.getChildAt(j); v.setPadding(0, 0, 0, 0); } } 
0
source

In my case, the problem was setting a fixed height for the custom layout that I use for tabs. Using match_parent my problem.

0
source

Source: https://habr.com/ru/post/1244636/


All Articles