在项目中需要使用materialdesign包中的tabLayout控件,正常在xml中加入tabLayout。
<android.support.design.widget.TabLayout
android:id="@+id/landmark_list_tablayout"
android:layout_width="match_parent"
android:layout_height="@dimen/landmark_tab_layout_height"/>
运行代码报错如下:
Error inflating class android.support.design.widget.TabLayout
后来发现如果要使用material design包的控件,theme要使用AppCompat的主题。于是将styles中的主题改为:
<style
name="FBaseAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTitleBackgroundStyle">@style/FTitlebarBackground</item>
<item name="android:windowTitleSize">@dimen/f_titlebar_height</item>
<item name="android:background">@null</item>
<item name="android:windowNoTitle">false</item>
</style>
运行,这次还是crash,不过刚才的问题消失了,新的错误是:
You cannot combine custom titles with other title features。
原来在项目中使用了自定义的titlebar:
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.f_titlebar);
使得我们自定义的titlebar和使用的主题发生冲突,最后在自定义的主题中增加false
解决问题:
<style name="FBaseAppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowTitleBackgroundStyle">@style/FTitlebarBackground</item>
<item name="android:windowTitleSize">@dimen/f_titlebar_height</item>
<item name="android:background">@null</item>
<item name="android:windowNoTitle">false</item>
</style>