I am trying to change the text color of a TextView
. This is the code I am using:
XML:
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/eks"
/>
Java:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedule);
Intent intent = getIntent();
TextView txt = (TextView) findViewById(R.id.textView1);
txt.setTextColor(Color.parseColor("#FFFFFF")); }
Any ideas why the text color is not changing?
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/eks"
android:textColor="#ffffff" />
try this
I would use the Android Resources system to get everything jiving all nice and pretty.
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="white">#FFFFFF</color>
</resources>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/eks"
android:textColor="@color/white" />
</LinearLayout>
如果使用主题Theme.AppCompat.Light.NoActionBar
的扩展,则TextView
颜色将无法再更改。
尝试这个:
txt.setTextColor(Color.WHITE);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.