[英]TextView text color does not change
我正在嘗試更改TextView
的文本顏色。 這是我正在使用的代碼:
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")); }
有什么想法為什么文本顏色沒有改變?
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/eks"
android:textColor="#ffffff" />
嘗試這個
我將使用Android資源系統來使所有事情變得井井有條。
<?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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.