英文:
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
<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=nullmChangingConfigurations=0mStateSpecs=[[-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.
答案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
<TextView<br>
android:color="#000000"<br>
android:layout_width="wrap_content"<br>
android:layout_height="wrap_content"<br>
android:text="TextView color"<br>
android:textAlignment="gravity"<br>
android:textAllCaps="false"<br>
android:textSize="16dp"<br>
android:textStyle="bold"<br>
android:gravity="left|center"<br>
android:layout_marginLeft="20dp"<br>
android:padding="12dp" />
答案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
<item name="android:textColor">@color/textColorPrimaryLight</item>
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论