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

huangapple go评论69阅读模式
英文:

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

问题

Text color is grey as shown below, i have not set any default color in sytles.xml.
As you can see there is a difference between the spinner text color and the textview color.

color difference between Spinner and textview text

<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" />

I ran the ColorStateList oldColors = textView.getTextColors(); i got the below result.

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

Is the text color is due to this style, my 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" />
</resources>

All i want is regular black for texts. And i don't want to add change anything.

英文:

Text color is grey as shown below, i have not set any default color in sytles.xml.
As you can see there is a difference between the spinner text color and the textview color.

color difference between Spinner and textview text

&lt;TextView
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:text=&quot;TextView color&quot;
    android:textAlignment=&quot;gravity&quot;
    android:textAllCaps=&quot;false&quot;
    android:textSize=&quot;16dp&quot;
    android:textStyle=&quot;bold&quot;
    android:gravity=&quot;left|center&quot;
    android:layout_marginLeft=&quot;20dp&quot;
android:padding=&quot;12dp&quot;    /&gt;


    &lt;Spinner
        android:layout_width=&quot;192dp&quot;
        android:layout_height=&quot;49dp&quot;
        android:layout_marginEnd=&quot;16dp&quot;
        android:layout_marginRight=&quot;16dp&quot;
        android:entries=&quot;@array/spinner_items&quot;
        android:padding=&quot;10dp&quot;
        android:spinnerMode=&quot;dropdown&quot;

         /&gt;

I ran the ColorStateList oldColors = textView.getTextColors(); i got the below result.

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

Is the text color is due to this style, my Styles.xml:

 &lt;resources&gt;
&lt;!-- Base application theme. --&gt;
&lt;style name=&quot;AppTheme&quot; parent=&quot;Theme.AppCompat.Light&quot;&gt;
    &lt;!-- Customize your theme here. --&gt;
    &lt;item name=&quot;colorPrimary&quot;&gt;@color/colorPrimary&lt;/item&gt;
    &lt;item name=&quot;colorPrimaryDark&quot;&gt;@color/colorPrimaryDark&lt;/item&gt;
    &lt;item name=&quot;colorAccent&quot;&gt;@color/colorAccent&lt;/item&gt;
&lt;/style&gt;

&lt;style name=&quot;AppTheme.AppBarOverlay&quot; parent=&quot;ThemeOverlay.AppCompat.Dark.ActionBar&quot; /&gt;

&lt;style name=&quot;AppTheme.PopupOverlay&quot; parent=&quot;ThemeOverlay.AppCompat.Light&quot; /&gt;

</resources>

All i want is regular black for texts. And i don't want to add change anything.

答案1

得分: 1

<TextView
    android:color="#000000"
    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" />
英文:

Add color property in your TextView

&#60;TextView<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:color="#000000"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:layout_width="wrap_content"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:layout_height="wrap_content"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:text="TextView color"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:textAlignment="gravity"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:textAllCaps="false"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:textSize="16dp"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:textStyle="bold"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:gravity="left|center"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:layout_marginLeft="20dp"<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;android:padding="12dp" /&#62;

答案2

得分: 0

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

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

我寻找的原因是我想要实现暗模式。下面的文章帮助了我解决这个问题。基本上,我需要使用两个styles.xml 来实现暗模式。

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

英文:

Looks like that is the default color of text. So i have to force it to use regular black in Styles.xml

&lt;item name=&quot;android:textColor&quot;&gt;@color/textColorPrimaryLight&lt;/item&gt;

The reason i was looking for is i want to implement Dark mode. Below article helped my issue. Basically i have to use 2 styles.xml to implement dark mode.

How to officially support Dark Mode in your apps?

huangapple
  • 本文由 发表于 2020年10月19日 16:25:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/64423652.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定