繁体   English   中英

Java Android,默认文本视图颜色为灰色,看起来像提示文本颜色,如何纠正?

[英]Java Android, Default textview color is grey, looks like hint text color, how to correct it?

文本颜色为灰色,如下所示,我没有在 sytles.xml 中设置任何默认颜色。 如您所见,微调文本颜色和文本视图颜色之间存在差异。

Spinner 和 textview 文本之间的颜色差异

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="TextView color"
    android:textAlignment="gravity"
    android:textAllCaps="false"
    android:textSize="16dp"
    android:textStyle="bold"
    android:gravity="left|center"
    android:layout_marginLeft="20dp"
android:padding="12dp"    />


    <Spinner
        android:layout_width="192dp"
        android:layout_height="49dp"
        android:layout_marginEnd="16dp"
        android:layout_marginRight="16dp"
        android:entries="@array/spinner_items"
        android:padding="10dp"
        android:spinnerMode="dropdown"

         />

我跑了ColorStateList oldColors = textView.getTextColors(); 我得到了以下结果。

ColorStateList{mThemeAttrs=nullmChangingConfigurations=0mStateSpecs=[[-16842910], []]mColors=[603979776, -1979711488]mDefaultColor=-1979711488}

文字颜色是由于这种风格,我的Styles.xml:

 <resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

我想要的只是文本的常规黑色。 而且我不想添加任何更改。

在 TextView 中添加颜色属性

<文本视图
机器人:颜色=“#000000”
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView 颜色"
机器人:文本对齐=“重力”
机器人:textAllCaps =“假”
android:textSize="16dp"
android:textStyle="粗体"
机器人:重力=“左|中心”
android:layout_marginLeft="20dp"
android:padding="12dp" />

看起来这是文本的默认颜色。 所以我必须强制它在 Styles.xml 中使用常规黑色

<item name="android:textColor">@color/textColorPrimaryLight</item>

我正在寻找的原因是我想实现暗模式。 下面的文章帮助了我的问题。 基本上我必须使用2个styles.xml来实现暗模式。

如何在您的应用中正式支持暗模式?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM