使用多行标题

时间:2017-11-13 05:53:16

标签: android android-fragments android-tablayout android-tabs

我正在使用我在Tabs上设置的两个片段。

enter image description here

我有两个问题:

  1. 我想以多行而不是“...”
  2. 设置片段的标题

    这是添加片段并设置其标题的代码

    ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
    adapter.addFragment(new OneFragment(), "Current\nSubscription");
    
    1. 我想从标签上的图标和文字周围删除多余的空间,使其更紧凑,节省一些空间。

2 个答案:

答案 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" />