android center align the selected tab in tablayout

I took a look into TabLayout and tabContentStart only sets padding for its first child -> SlidingTabStrip, so I set it manually on both sides: public class CenteringTabLayout extends TabLayout { public CenteringTabLayout(Context context) { super(context); } public CenteringTabLayout(Context context, AttributeSet attrs) { super(context, attrs); } public CenteringTabLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, … Read more

Different tab width for TabLayout

You need to lower the weight of the LinearLayout of the corresponding tab. LinearLayout layout = ((LinearLayout) ((LinearLayout) tabLayout.getChildAt(0)).getChildAt(YOUR_TAB_NUMBER)); LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams) layout.getLayoutParams(); layoutParams.weight = YOUR_WEIGHT; // e.g. 0.5f layout.setLayoutParams(layoutParams); Hope that helps!

Can a custom view be used as a TabItem?

In certain cases, instead of the default tab view we may want to apply a custom XML layout for each tab. To achieve this, iterate over all the TabLayout.Tabs after attaching the sliding tabs to the pager: public class MainActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); // Get the ViewPager … Read more

How to set android TabLayout in the bottom of the screen?

I believe I have the best simple fix. Use a LinearLayout and set the height of the viewpager to be 0dp with a layout_weight=”1″. Make sure the LinearLayout has an orientation of vertical and that the viewpager comes before the TabLayout. Here is what mines looks like: <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.android.com/tools” android:layout_width=”match_parent” android:layout_height=”match_parent” tools:context=”.MainActivity” android:orientation=”vertical”> <include … Read more

Change the font of tab text in android design support TabLayout

If you are using TabLayout and you want to change the font you have to add a new for loop to the previous solution like this: private void changeTabsFont() { ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0); int tabsCount = vg.getChildCount(); for (int j = 0; j < tabsCount; j++) { ViewGroup vgTab = (ViewGroup) vg.getChildAt(j); int … Read more

android:textAllCaps=”false” not working for TabLayout design Support

UPDATE FOR DESIGN LIBRARY 23.2.0+ The original answer doesn’t work with design library 23.2.0 or later. Thanks for @fahmad6 pointed out in comment, in case someone missed that comment, I’ll put it here. You need to set both textAllCaps and android:textAllCaps to false to disable all capitalize setting. <style name=”MyCustomTextAppearance” parent=”TextAppearance.Design.Tab”> <item name=”textAllCaps”>false</item> <item name=”android:textAllCaps”>false</item> … Read more

Disable TabLayout

I had the same problem and I solved it disabling touch event on tabs with the following code: LinearLayout tabStrip = ((LinearLayout)mTabLayout.getChildAt(0)); for(int i = 0; i < tabStrip.getChildCount(); i++) { tabStrip.getChildAt(i).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return true; } }); }

ViewPager + RecyclerView issue in android

I see a lot of problems with your code, but let’s get your UI displaying the subcategories since that’s your main concern. Change the getItem in your adapter to this: @Override public Fragment getItem(int position) { ArrayList<SubcategoryModel> subcategories = filelist.get(position).getItems(); Log.v(“adapter”, “getitem” + String.valueOf(position)+subcategories.size()); return FirstFragment.create(position,subcategories); } What caused the problem: Let’s focus on ArrayList<SubcategoryModel> … Read more