【发布时间】:2016-09-27 17:51:01
【问题描述】:
最近我更改了一些应用程序,但由于我不理解“setTextColor”方法的原因,它似乎不再有效。
在我的 XML 中,我有一个列表视图,并以编程方式在此列表视图中添加 TextView。
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);
但是无论我做什么,这个文本都是白色的。 为什么?
【问题讨论】:
-
尝试删除“setTextAppearance”