最近我改变了一点我的应用程序,并且出于某种原因,我不明白“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“ –