【问题标题】:tabs in tablayout not displayingtablayout中的标签不显示
【发布时间】:2018-06-12 06:55:26
【问题描述】:

我有一个非常简单的标签制作代码,这是我的布局代码:

<android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:background="@color/red"
            app:tabGravity="fill"
            app:tabIndicatorColor="#F48917"
            app:tabIndicatorHeight="2.5dp"
            app:tabMode="fixed"
            app:tabTextColor="#fff">

        </android.support.design.widget.TabLayout>

它在一个线性布局内

​​>

这是我制作标签的java代码:

        tabLayout = (TabLayout) findViewById(R.id.tabs);

    TabLayout.Tab firstTab = tabLayout.newTab(); // Create a new Tab names "First Tab"
    firstTab.setText("First Tab"); // set the Text for the first Tab
    firstTab.setIcon(R.drawable.ic_launcher); // set an icon for the first tab
    tabLayout.addTab(firstTab);

问题是,它不会在 android api +21 上显示一个没有任何内容的空选项卡,但它会在 21 以下显示 android 中的选项卡

我该如何解决这个问题?这是什么问题?

这是 api 21+ 上的图像: 这是21以下的api上的图像

【问题讨论】:

  • 你能把@john smoth 的屏幕截图发上来吗
  • k 得到它现在尝试给android:layout_height="wrap_content" 并删除 app:tabGravity 和 app:tabMode 并让我知道
  • @war_Hero 我试过但没用
  • 发布你的整个 xml

标签: android android-tabhost android-tablayout


【解决方案1】:

XML:

<android.support.design.widget.TabLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/tabLayout"/>

代码是

TabLayout tabLayout= (TabLayout) findViewById(R.id.tabLayout);
tabLayout.addTab(tabLayout.newTab().setText("first").setIcon(R.drawable.ic_launcher));

别忘了添加依赖

compile 'com.android.support:design:XXX'

其中 XXX 是支持设计的最低版本

【讨论】:

    猜你喜欢
    • 2016-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    • 1970-01-01
    • 2021-10-19
    相关资源
    最近更新 更多