EditText和TextView的textColorPrimary在API < 21下不遵循主题颜色。

4

在为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

  1. android:textColor=应该包含什么内容?或者
  2. 我如何查看ActionBar支持生成的TextView(类似于浏览器F12)?这样我就可以应用相同的样式。

2
дҪ еә”иҜҘдҪҝз”Ё?textColorPrimaryгҖӮеңЁAPI <21дёӯпјҢtextColorPrimaryз”ұAppCompatжҸҗдҫӣгҖӮеә“еұһжҖ§дёҚйңҖиҰҒеүҚзјҖandroid:гҖӮ - Vikram
1
抱歉,至少在API19上它不起作用。现在,我只定义了一个使用我定义的颜色的样式,并将该样式分配给TextView。我认为这是一个错误,因为只有android:textColorPrimary不能正常工作,但android:background可以正常工作。 - CallMeLaNN
1个回答

4

textcolor属性的正确值应该是:

android:textColor="?android:attr/textColorPrimary"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接