对于将从写更改为只读的表单,我需要一个EditText以TextView的形式出现。我发现了一段在布局中实现这一点的有用代码:
<EditText android:id="@+id/title"
android:layout_width="fill_parent"
style="?android:attr/textViewStyle"
android:background="@null"
android:textColor="@null" />
我需要动态地(而不是在布局中)执行此操作。我知道使用setBackgroundResource(null)
可以将背景设置为@null
。因为setTextColor(int color)
采用int
,所以我认为必须选择特定的颜色。选择与@null
等效的正确颜色是什么?默认主题的颜色?或者有更好的方法吗?
您可以像一样在字符串.xml中创建颜色
<color name="transparent">#00000000</color>
然后你可以将其分配给类似
txtTitle.setTextColor(getResources().getColor(R.color.transparent));
#00000000
等于零。
您可以在任何View
上调用这些方法来禁用编辑或单击。它将有效地使视图只读。将它们设置为true
以重新启用它们。
view.setFocusable(false);
view.setClickable(false);
view.setLongClickable(false);