Android TabLayout tabPaddingTop and tabPaddingBottom not removed

Here is my XML tab layout

<android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="@dimen/custom_tab_layout_height" android:background="@color/tab_background_primary" app:tabGravity="fill" app:tabIndicatorColor="@color/primary_white" app:tabIndicatorHeight="3dp" app:tabMinWidth="120dp" app:tabMode="scrollable" app:tabPaddingStart="-1dp" app:tabPaddingEnd="-1dp" app:tabPaddingTop="1dp" app:tabPaddingBottom="1dp" /> 

It removes the horizontal padding between tabs, but not tabPaddingTop and tabPaddingBottom.

How to remove top and bottom padding so that each tab matches tabLayout height?

enter image description here

Custom view for each tab

 <?xml version="1.0" encoding="utf-8"?> <TextView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/tab" android:textColor="@color/primary_white" android:textSize="14sp" android:textStyle="bold" android:gravity="fill" android:fontFamily="@string/font_fontFamily_medium"/> 

I also tried using Linear Layout with Imagview and Textview as a custom view.

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="match_parent" android:gravity="fill" android:layout_height="match_parent"> <ImageView android:id="@+id/tab_logo" android:layout_width="wrap_content" android:layout_height="match_parent" android:src="@mipmap/ic_settings_light"/> <TextView android:layout_width="wrap_content" android:layout_height="match_parent" android:id="@+id/tab_title" android:textColor="@color/primary_white" android:textSize="14sp" android:textStyle="bold" android:gravity="center" android:text="test" android:fontFamily="@string/font_fontFamily_medium"/> </LinearLayout> 

And this is how I overestimated the custom tab view (for a custom view using textView)

 TextView tabTwo = (TextView) LayoutInflater.from(this).inflate(R.layout.custom_tab, null); tabTwo.setText("CASH IN"); tabTwo.setBackgroundColor(Color.parseColor("#EC5A0B")); tabTwo.setCompoundDrawablesWithIntrinsicBounds(R.mipmap.ic_action_cash_light, 0, 0, 0); tabLayout.getTabAt(1).setCustomView(tabTwo); 

As you can see, I am trying to give different background colors for each tab. But there are still indents from above and below.

+2
source share
3 answers

I think the TabLayout Android design library has default add-ons, for example, what you can see here

Another recommendation I can recommend you is to use Google IO SlidingTabLayout (don't forget to copy SlidingTabStrip )

The usage is simple, just include in your layout:

 <com.myapp.ui.widget.SlidingTabLayout android:id="@+id/main_view_pager_tab" android:layout_width="match_parent" android:layout_height="@dimen/tabs_height" android:background="@color/white" /> 

and then in your activity set viewpager and listener (if you want)

  mainViewPagerTab.setViewPager(mainViewPager); mainViewPagerTab.setOnPageChangeListener(onPageChangeListener); 
0
source

That was the only solution.

fooobar.com/questions/1244636 / ...

Try the code by adding your tabs to your tab.

 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); } 
0
source

I have a better solution for this problem, check the code below and this will help.

My XML tab file looks like this:

 <RelativeLayout android:layout_height="30dp" android:background="#333333" android:layout_width="match_parent"> <android.support.design.widget.TabLayout android:id="@+id/tabs" android:layout_width="match_parent" android:layout_height="wrap_content" app:tabTextAppearance="@style/MineCustomTabText" style="@style/tab_bassr" app:tabMode="scrollable"/> </RelativeLayout> 

the relative layout will reduce the upper and lower margins

 <style name="tab_bassr" parent="TextAppearance.Design.Tab"> <item name="android:layout_width">match_parent</item> <item name="android:tabStripEnabled">false</item> <item name="tabPaddingStart">5dp</item> <item name="tabPaddingEnd">5dp</item> </style> <style name="MineCustomTabText" parent="TextAppearance.Design.Tab"> <item name="android:textSize">14sp</item> </style> 

Style file for left and right fill and text size.

0
source

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


All Articles