对于AppCompatActivity,TextView颜色始终为白色 [英] TextView color is always white for AppCompatActivity
问题描述
在蛋白软糖之前的设备上,TextView
的文本颜色始终为白色.即使我在XML中使用黄色或黑色,除棉花糖外,它始终是白色.
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.
在运行时,它将在所有设备上正常运行.以前,当我使用Eclipse时,一切都可以找到,但是在Android Studio中,它不是从XML中获取属性.
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.
我搜索过的所有问题都说将Theme.AppCompat
更改为Theme.AppCompat.Light
,但是除了将白色更改为黑色之外,此操作无济于事.我相信这里有风格上的错误.这是我的样式代码:
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>
这是我的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>
推荐答案
我终于得到了我的问题的答案,实际上我正在使用最新版本的支持库,该库正在创建问题,我将所有与我的同事项目进行比较,因为他的应用正在运行很好..
用这个
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将为弹出窗口提供一个较新的版本,但不要使用该版本,因为24版本处于alpha阶段.
studio will give popup a newer version is also available but don't use that as 24 version is in alpha stage.
这篇关于对于AppCompatActivity,TextView颜色始终为白色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!