TextView color is always white for AppCompatActivity

感情迁移 提交于 2019-12-10 16:34:08

问题


The text color of a TextView is always white on pre-Marshmallow devices. Even if I am using yellow or black in my XML, it is always white except on Marshmallow.

At run time it will work fine on all devices. Previously, when I was using Eclipse, everything was working find but in Android Studio it is not taking the attribute from the XML.

All of the questions I have searched say to change Theme.AppCompat to Theme.AppCompat.Light but this does nothing except change white to black. I believe there is a style mistake. Here is my style code:

 <style name="AppBaseTheme" parent="Theme.AppCompat">
        <item name="colorPrimary">@color/khaki</item>
        <item name="colorPrimaryDark">@color/khaki</item>
        <item name="colorAccent">@color/my_yellow</item>

        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.
        -->
    </style>

Here is my xml

 <?xml version="1.0" encoding="utf-8"?>
  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="48dp">
   <ImageView
    android:id="@+id/icon1"
    android:layout_width="30dp"
    android:layout_height="30dp"
    android:layout_alignParentLeft="true"
    android:layout_marginLeft="12dp"
    android:layout_marginRight="12dp"
     android:src="@drawable/sj_icon"
    android:layout_centerVertical="true"/>

   <TextView
    android:id="@+id/title"
    android:layout_width="wrap_content"
    android:layout_height="50dp"
    android:layout_alignLeft="@+id/icon1"
    android:layout_alignParentTop="true"
    android:layout_marginLeft="32dp"
    android:gravity="center_vertical"
    android:minHeight="34dp"
    android:paddingLeft="7dp"
    android:text="hello"
    android:textColor="@color/my_yellow"
    android:textSize="18sp" />

   </RelativeLayout>

回答1:


I finally got the answer of my problem actually I was using latest version of support library that was creating problem I compare everything with my colleague project as his app was working fine..
use this

compile 'com.android.support:appcompat-v7:23.1.1'

studio will give popup a newer version is also available but don't use that as 24 version is in alpha stage.




回答2:


I faced a problem similar to this (in a widget, the text color was white if the average of RGB values is more than half the max value and black if not)

I was testing the app in a phone having the "high contrast text" feature enabled, so the solution was disabling it.



来源:https://stackoverflow.com/questions/35987952/textview-color-is-always-white-for-appcompatactivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!