我需要一个EditText作为TextView显示,表单将从写入变为只读。我在布局中找到了一个有用的代码片段:
<EditText android:id="@+id/title"
android:layout_width="fill_parent"
style="?android:attr/textViewStyle"
android:background="@null"
android:textColor="@null" />
我需要动态执行此操作(不在布局中)。我知道可以使用@null
将背景设置为setBackgroundResource(null)
。由于setTextColor(int color)
需要int
,我认为必须选择特定的颜色。选择的正确颜色是什么,相当于@null
?默认主题的颜色?或者有更好的方法吗?
答案 0 :(得分:0)
您可以在string.xml中创建颜色,如
<color name="transparent">#00000000</color>
然后你可以把它分配给
txtTitle.setTextColor(getResources().getColor(R.color.transparent));
#00000000
等于null。
答案 1 :(得分:0)
您可以在任何View
上调用这些方法来禁用编辑或单击。它将有效地使视图只读。将它们设置为true
以重新启用它们。
view.setFocusable(false);
view.setClickable(false);
view.setLongClickable(false);