I found the below documentation on how to set a customView
. But when I change the id
in my layout to "text1" and "icon", setText()
and setIcon()
do not work.
public TabLayout.Tab setCustomView (int layoutResId)
Set a custom view to be used for this tab.
If the inflated layout contains a
TextView
with an ID oftext1
then that will be updated with the value given tosetText(CharSequence)
. Similarly, if this layout contains anImageView
with ID icon then it will be updated with the value given tosetIcon(Drawable)
.
Can anyone give me an example of how this works?
Java code:
TabLayout.Tab tabAdd = tabLayout.getTabAt(0);
tabAdd.setCustomView(R.layout.tab_layout_custom_view);
tabAdd.setText("Add");
tabAdd.setIcon(R.mipmap.add_tab).setText("Add");
Layout Code:
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:id="@+id/icon"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0"
android:id="@+id/text1"
android:gravity="center"
android:layout_below="@+id/icon" />