1

I can't set text with multi-line in TabLayout in my application.

How can I set text with multi-line in TabLayout?

I want to remove "..." in TabLayout text.

Hardik Vaghasiya
  • 298
  • 1
  • 3
  • 11

2 Answers2

0

See below link that will help you to set multiline in Tab of Tab Layout

Remove line break in TabLayout

or

set your custom text view like bellow in tab_item layout

 <TextView
    android:id="@+id/tvTabTitle"
    style="@style/wrapParentRegularFont"
    android:maxLines="2"        
    android:textSize="@dimen/_10sdp" />

<android.support.design.widget.TabLayout
    android:id="@+id/tlMyJobCart"
    style="@style/widthMatchParent"
    android:layout_marginLeft="@dimen/_20sdp"
    android:layout_marginRight="@dimen/_20sdp"
    app:tabGravity="fill"
    app:tabIndicatorColor="@color/color_radical_red"
    app:tabMode="fixed" />

And then set your text view to Tab layout like

private TabLayout tlMyTabLayout;
tlMyTabLayout = (TabLayout) view.findViewById(R.id.tlMyTabLayout);
tlMyTabLayout.addTab(tlMyTabLayout.newTab().setCustomView(R.layout.tab_item), true);
Community
  • 1
  • 1
Nrup Parikh
  • 386
  • 1
  • 6
0

You can set a customView (a textView, preferably) by doing this:

TabLayout tabLayout = (TabLayout) findViewById(R.id.tabLayout);
TextView tv = new TextView(this);
tv.setLines(2)
tv.setMaxLines(2); //set max lines to 2 
tv.setText("your multi-line text is here");
tabLayout.addTab(tabLayout.newTab().setCustomView(tv));

In case, you wish to set customView to already added tabs, you can get the tab and set the customView (TextView) to it:

tabLayout.getTabAt(0).setCustomView(tv); //postion 0, 1, 2...
Nilesh Singh
  • 1,750
  • 1
  • 18
  • 30