java 如何制作无法编辑的 EditText?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7480134/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 20:10:13  来源:igfitidea点击:

How to make EditText that cannot be editted?

javaandroidandroid-edittext

提问by Pattabi Raman

I am trying to make the editText that shows the text but not as editable type. I cant use textview there because i am using same component for entering the values. How to achieve it? Any help is really appreciated and thanks in advance.

我正在尝试制作显示文本但不是可编辑类型的 editText。我不能在那里使用 textview,因为我使用相同的组件来输入值。如何实现?任何帮助都非常感谢并提前致谢。

回答by Mohammed Azharuddin Shaikh

editText.setFocusable(false);editText.setClickable(false);the two property which turn EditText to non focusable and unclickable which leads to a non editable Edittext

editText.setFocusable(false);editText.setClickable(false);将 EditText 变为不可聚焦和不可点击的两个属性,从而导致不可编辑的 Edittext

回答by Awais Tariq

Make EditText Read only.

使 EditText 只读。

Like this:

像这样:

android:enabled="false"

Or from code: edittext.setEnabled(false)or edittext.setFocusable(false)or edittext.setFocusableinTouchMode(false)

或代码: edittext.setEnabled(false)edittext.setFocusable(false)edittext.setFocusableinTouchMode(false)

回答by Niranj Patel

try this....

试试这个....

EditText.setFilters(new InputFilter[] {new InputFilter()
{
    @Override
    public CharSequence filter(CharSequence source, int start,
                int end, Spanned dest, int dstart, int dend) 
    {
        return source.length() < 1 ? dest.subSequence(dstart, dend) : "";

    }
 }
});

回答by ilango j

try like this

像这样尝试

android:editable="false"

回答by adatapost

Simply, open the layout file and add android:editable="false"attribute.

只需打开布局文件并添加android:editable="false"属性。

<EditText 
  android:id="@+id/editText1" 
  android:layout_height="wrap_content" 
 android:layout_width="match_parent"
 android:editable="false"
>

回答by Rajesh Sharma

hi if you use edit text so u give this property in edit text

嗨,如果您使用编辑文本,那么您在编辑文本中提供此属性

android:hint="write any thing", but dont use Android:text=""

android:hint="write any thing",但不要使用 Android:text=""