簡體   English   中英

TextView文字顏色不變

[英]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資源系統來使所有事情變得井井有條。

/res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="white">#FFFFFF</color>
</resources>

/res/layout/my_layout.xml

<?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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM