我正在使用我在Tabs上设置的两个片段。
我有两个问题:
这是添加片段并设置其标题的代码
ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new OneFragment(), "Current\nSubscription");
答案 0 :(得分:3)
尝试使用以下代码设置您的TabLayout
标题
TextView tabOne = new TextView(this);
tabOne.setText("Current"+ System.getProperty("line.separator") +"Subscription");
tabOne.setCompoundDrawablesWithIntrinsicBounds(0, R.drawable.ic_tab_favourite, 0, 0);
tabLayout.getTabAt(0).setCustomView(tabOne);
答案 1 :(得分:0)
Showing "..." in tab titles will not make a good UI experience I suggest that you should set tabmode to scrollable and let tab titles take as much space they want.
<android.support.design.widget.TabLayout
android:id="@+id/htab_tabs"
android:layout_width="wrap_content"
android:layout_height="?attr/actionBarSize"
android:layout_gravity="bottom"
app:tabIndicatorColor="@android:color/white"
app:tabMode="scrollable" />