最近我改變了一點我的應用程序,並且出於某種原因,我不明白「setTextColor」方法似乎不再適用。以編程方式在Android庫中的TextView中設置setTextColor
在我的XML中,我有一個列表視圖,我以編程方式在此列表視圖中添加TextViews。
XML:
<LinearLayout
android:id="@+id/activity_game_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="left|top"
android:orientation="vertical"
android:padding="7dp" >
</LinearLayout>
的Java:
textView = new TextView(getContext());
textView.setText("some text");
textView.setTextSize(20f);
textView.setGravity(Gravity.CENTER);
textView.setTextColor(Color.BLACK);
textView.setTextAppearance(getContext(), android.R.style.TextAppearance_Medium);
addView(textView);
但是這段文字是白色的無論我做什麼。 爲什麼?
這就是答案http://stackoverflow.com/questions/6177273/textview-settextcolor-not-working – Proxytype
嘗試刪除「 setTextAppearance「 –