【问题标题】:Set Fragment on Tab with multi line title在具有多行标题的选项卡上设置片段
【发布时间】:2018-04-25 18:05:35
【问题描述】:

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

我有两个问题:

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

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

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

【问题讨论】:

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


    【解决方案1】:

    尝试使用以下代码设置您的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);
    

    【讨论】:

      【解决方案2】:

      在标签标题中显示“...”不会带来良好的 UI 体验我建议您应该将标签模式设置为可滚动并让标签标题占用他们想要的尽可能多的空间。

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

      【讨论】:

      • android:layout_height="?attr/actionBarSize" 将高度设置为 actionBarSize 删除了所有不需要的空格。谢谢
      • 它是action-bar的高度如果你没有得到那么你也可以像56.0dip一样手动定义
      • 否则你用 android:layout_height="56.0dip" 替换 android:layout_height="?attr/actionBarSize" 这个
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多