android - tablayout中的标签不显示
问题描述
我有一个非常简单的代码来制作标签,这是我的布局代码:
<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上显示一个没有任何内容的空标签,但它在android 21以下显示标签
我怎样才能解决这个问题 ?这是什么问题?
解决方案
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 是支持设计的最低版本
推荐阅读
- android - android studio 在 java android studio 中创建的自制启动器上显示小部件
- sql - 根据日期范围sql添加值
- java - orderByChild().equalTo() Firebase 复杂度
- datatables - 来自谷歌表的 DataTables 数据不起作用
- ios - 为什么 xcode 无法识别与配置文件关联的证书?
- ios - 支持的部署目标版本范围是 9.0 到 14.55 在 iOS 模拟器上运行 Flutter App 时出现错误
- javascript - 如何使用javascript循环遍历每个表行并交换两行
- reactjs - 当应用更多层视图组件时反应原生应用崩溃
- c++ - c++ 是否有相当于 Typescripts 的交集类型?
- google-bigquery - Firebase Analytics 到 BigQuery 导出不起作用