android生成不可编辑文件格式,android-EditText不可编辑

android-EditText不可编辑

我正在尝试使用以下代码使EditText不可编辑:

android:inputType="text"

android:editable="false"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:text="@string/result" />

我必须添加以下行以使其不可编辑

android:focusable="false"

难道我做错了什么?

非常感谢你

9个解决方案

125 votes

android:editable应该可以工作,但是已经过时了,您应该改用android:inputType="none"。

或者,如果您想在代码中执行此操作,则可以执行以下操作:

EditText mEdit = (EditText) findViewById(R.id.yourid);

mEdit.setEnabled(false);

这也是一个可行的选择:

EditText mEdit = (EditText) findViewById(R.id.yourid);

mEdit.setKeyListener(null);

如果您要使android:editable不可编辑,我建议使用android:inputType="none"小部件而不是EditText,因为在这种情况下使用EditText似乎毫无意义。

编辑:更改了一些信息,因为我发现不赞成使用android:editable,您应该使用android:inputType="none",但是在android代码上有关于此的错误; 所以请检查一下。

Jean-Philippe Roy answered 2020-06-26T13:29:46Z

10 votes

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:id="@+id/editTexteventdate"

android:background="@null"

android:hint="Date of Event"

android:textSize="18dp"

android:textColor="#fff"

android:editable="false"

android:focusable="false"

android:clickable="false"

/>

加上这个

android:editable =“ false”

android:focusable =“ false”

android:clickable =“ false”

它对我的工作

Dharmendra Mishra answered 2020-06-26T13:30:23Z

8 votes

如果您想使EditText无法通过代码进行编辑:

void disableInput(EditText editText){

editText.setInputType(InputType.TYPE_NULL);

editText.setTextIsSelectable(false);

editText.setOnKeyListener(new View.OnKeyListener() {

@Override

public boolean onKey(View v,int keyCode,KeyEvent event) {

return true; // Blocks input from hardware keyboards.

}

});

}

如果要删除EditText的水平线,只需添加:

editText.setBackground(null);

如果要让用户复制EditText的内容,请使用:

editText.setTextIsSelectable(true);

vovahost answered 2020-06-26T13:30:54Z

6 votes

我想我来晚了,但请结合使用以下内容使其有效:

android:inputType="none"

android:enabled="false"

Akshay Taru answered 2020-06-26T13:31:14Z

6 votes

如果您确实要使用editText而不是textView,请考虑使用以下三种方法:

android:focusable="false"

android:clickable="false"

android:longClickable="false"

编辑:“ longClickable”属性禁用导致“粘贴”和/或“全选”选项显示为工具提示的长按操作。

Mofe Ejegi answered 2020-06-26T13:31:38Z

3 votes

在您的xml edittext中添加以下行。

android:editable="false"

android:focusable="false"

android:clickable="false"

它为我工作

Deepak Jain answered 2020-06-26T13:32:06Z

2 votes

用这个:

EditText edtText = (EditText) findViewById(R.id.yourEditTextId);

edtText.setEnabled(false);

您也可以在xml文件中使用它。

Gourav Samre answered 2020-06-26T13:32:35Z

1 votes

我也有这个问题。

我这样做:

android:layout_width="30dp"

android:layout_height="wrap_content"

android:id="@+id/yourid"

android:editable="false"

android:inputType="none" />

Cogiat84 answered 2020-06-26T13:32:59Z

0 votes

我的要求是要具有edittext的外观,并在单击时打开一个弹出窗口,但是将其启用为false将不允许对其使用单击侦听器。 所以我以这种方式做到了。

android:id="@+id/tvCustomerAge"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:minWidth="80dp"

android:layout_alignParentEnd="true"

android:drawableRight="@drawable/arrow_down"

android:inputType="none"

android:focusable="false"

android:clickable="true"

tools:text="24"/>

Anupriya answered 2020-06-26T13:33:23Z

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值