使用多行标题在选项卡上设置片段

pam*_*amo 1 android android-fragments android-tabs android-tablayout

我正在处理我在选项卡上设置的两个片段。

在此处输入图片说明

我有两个问题:

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

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

ViewPagerAdapter adapter = new ViewPagerAdapter(getSupportFragmentManager());
adapter.addFragment(new OneFragment(), "Current\nSubscription");
Run Code Online (Sandbox Code Playgroud)
  1. 我想从选项卡上的图标和文本周围删除额外的空间,使其更紧凑并节省一些空间。

Gok*_*oku 5

尝试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);
Run Code Online (Sandbox Code Playgroud)