尝试设置我的应用以使用Material Design:
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:colorPrimary">@color/colorPrimary</item>
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="android:colorAccent">@color/colorAccent</item>
android:
的项目,则不会应用颜色。android:
的项目 - 应用崩溃: Unable to start activity ComponentInfo{com.foo.bar/com.foo.bar.MainActivity}: android.view.InflateException: Binary XML file line #9: Error inflating class android.support.design.widget.TabLayout
问题:
修改
清单文件是:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.foo.bar">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
EDIT2
activity_main.xml中:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.design.widget.TabLayout
android:id="@+id/tl_periods"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:tabMinWidth="100dp"
app:tabMode="scrollable"/>
答案 0 :(得分:3)
您的应用主题不是AppCompat
主题的后代,而您的TabLayout
来自支持包。
你要么必须坚持使用AppCompat
主题和观点,要么完全是支持包独立,否则这些讨厌的问题将会上升。