【发布时间】:2016-02-27 23:13:00
【问题描述】:
我有一个包含EditText 和Button 的活动。 EditText 中的数据一开始是不可编辑的,但是当按下 Button 时它变成可编辑的。我曾尝试在 xml 布局中使用 android:editable="false",但它不起作用。有人可以帮我解决这个问题吗?
【问题讨论】:
我有一个包含EditText 和Button 的活动。 EditText 中的数据一开始是不可编辑的,但是当按下 Button 时它变成可编辑的。我曾尝试在 xml 布局中使用 android:editable="false",但它不起作用。有人可以帮我解决这个问题吗?
【问题讨论】:
您需要先在 xml 布局中将 TextEdit 可编辑属性设置为 false :
<EditText
...
android:id="@+id/input"
android:clickable="false" />
然后在单击按钮时,将 TextEdit 设置为可编辑:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
input = (EditText) findViewById(R.id.input);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
input.setClickable(true);
}
});
}
【讨论】:
editable 属性仅通过 XML 以编程方式公开,您应该使用 setEnabled 或 setFocusable 或 setClickable。但是,使用这些方法时,您将无法选择和复制文本...代码已更新。
editText.setEnabled(true); or editText.setEnabled(false);
如果不能工作,那么Editable false
【讨论】:
<EditText
...
android:id="@+id/urId"
android:clickable="True" />
这对我有用,试试你的运气。
【讨论】:
code markdown 中添加一行。