簡體   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