【发布时间】:2015-03-11 04:13:27
【问题描述】:
在设置工具栏视图的样式以使其适用于 API 21 及以下版本时存在一些问题,但考虑到我有这个 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 @color/white。
但是我仍然相信有可能,因为在Activity.onCreate() 中使用setSupportActionBar((Toolbar) findViewById(R.id.app_bar));“自动生成”TextView 标题,我可以看到TextView 跟随我的textColorPrimary。
-
android:textColor=中应该包含什么内容?或 - 我怎样才能看到ActionBar支持生成的TextView(比如浏览器F12)?所以我可以应用同样的方法。
【问题讨论】:
-
您应该使用
?textColorPrimary。在 API textColorPrimary 由 AppCompat 提供。库属性不需要android:前缀。 -
对不起,它至少对 API19 不起作用。现在,我只需定义一个使用我定义的颜色的样式并将该样式分配给
TextView。我认为这是一个错误,因为只有android:textColorPrimary不工作,但android:background工作正常。
标签: android android-layout material-design