在为API 21及以下版本设计Toolbar视图样式时可能会遇到一些问题,但是请考虑我有这个styles.xml文件。
<!-- Base application theme. -->
<style name="AppTheme" parent="AppTheme.Base">
<!-- Customized theme for API < 21 -->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
</style>
<style name="AppToolbarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
<item name="android:background">@color/colorPrimary</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="android:textColorSecondary">@color/grey</item>
</style>
在我的screen1.xml工具栏中有这个。
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:theme="@style/AppToolbarTheme"
app:popupTheme="@style/AppPopupToolbarTheme"
android:id="@+id/app_bar">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar_text"
android:textColor="?android:textColorPrimary"
android:gravity="center"/>
<!-- other views here -->
</RelativeLayout>
</android.support.v7.widget.Toolbar>
"?android:textColorPrimary"
在API < 21中无效,会回退到使用暗色文本颜色而不是我的@color/white
。
然而,我仍然相信这是可能的,因为通过在Activity.onCreate()
中使用setSupportActionBar((Toolbar) findViewById(R.id.app_bar));
自动生成的TextView标题,我可以看到TextView遵循我的textColorPrimary
。
android:textColor=
应该包含什么内容?或者- 我如何查看ActionBar支持生成的TextView(类似于浏览器F12)?这样我就可以应用相同的样式。
?textColorPrimary
гҖӮеңЁAPI <21дёӯпјҢtextColorPrimary
з”ұAppCompatжҸҗдҫӣгҖӮеә“еұһжҖ§дёҚйңҖиҰҒеүҚзјҖandroid:
гҖӮ - VikramTextView
。我认为这是一个错误,因为只有android:textColorPrimary
不能正常工作,但android:background
可以正常工作。 - CallMeLaNN