This may help:
这可能会有所帮助:
if (cbProhibitEditPW.isChecked()) { // disable editing password
editTextPassword.setFocusable(false);
editTextPassword.setFocusableInTouchMode(false); // user touches widget on phone with touch screen
editTextPassword.setClickable(false); // user navigates with wheel and selects widget
isProhibitEditPassword= true;
} else { // enable editing of password
editTextPassword.setFocusable(true);
editTextPassword.setFocusableInTouchMode(true);
editTextPassword.setClickable(true);
isProhibitEditPassword= false;
}
I did it in a easier way , setEditable and setFocusable false. but you should check this.
我使用了一种更简单的方法,即setEdable和setFocailable False。但你应该检查一下这个。
How to replicate android:editable="false" in code?
如何在代码中复制android:edable=“False”?
Fetch the KeyListener value of EditText
by editText.getKeyListener()
and store in the KeyListener type variable, which will contain
the Editable property value:
通过editText.getKeyListener()获取EditText的KeyListener值,并存储在KeyListener类型变量中,该变量将包含可编辑属性值:
KeyListener variable;
variable = editText.getKeyListener();
Set the Editable property of EditText
to false as:
将EditText的Editable属性设置为False,如下所示:
edittext.setKeyListener(null);
Now set Editable property of EditText
to true as:
现在将EditText的可编辑属性设置为True,如下所示:
editText.setKeyListener(variable);
Note: In XML the default Editable property of EditText
should be true.
注意:在XML中,EditText的默认可编辑属性应为True。
How to do it programatically :
如何通过编程实现这一点:
To enable EditText use:
要启用编辑文本,请使用:
et.setEnabled(true);
To disable EditText use:
要禁用EditText,请使用:
et.setEnabled(false);
hope this one helps you out:
希望这篇文章能帮到你:
edittext1.setKeyListener(null);
edittext1.setCursorVisible(false);
edittext1.setPressed(false);
edittext1.setFocusable(false);
editText.setInputType(InputType.TYPE_NULL);
Once focus of edit text is removed, it would not allow you to type even if you set it to focusable again.
一旦删除了编辑文本的焦点,即使您再次将其设置为可聚焦,它也不允许您键入。
Here is a way around it
这里有一个绕过它的方法
if (someCondition)
editTextField.setFocusable(false);
else
editTextField.setFocusableInTouchMode(true);
Setting it true in setFocusableInTouchMode()
seems to do the trick.
在setFocusableInTouchModel()中将其设置为真似乎可以达到目的。
try this,
尝尝这个,
EditText editText=(EditText)findViewById(R.id.editText1);
editText.setKeyListener(null);
It works fine...
它工作得很好。
Try this it is working fine for me..
试试看,它对我来说很好。
EditText.setInputType(0);
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) : "";
}
}
});
editText.setFocusable(false);
editText.setClickable(false);
Since setEditable(false)
is deprecated, use textView.setKeyListener(null);
to make editText non-clickable.
由于setEdable(FALSE)已弃用,请使用extView.setKeyListener(NULL);使editText不可点击。
Since the setEditable(false)
is deprecated and we can't use it programmatically, we can use another way to solve it with setInputType(InputType.TYPE_NULL)
由于setEdable(FALSE)已弃用,并且我们不能以编程方式使用它,因此可以使用另一种方法使用setInputType(InputType.TYPE_NULL)来解决它
It means we change the input type of edit text. We set it to NULL so it becomes not editable.
这意味着我们改变了编辑文本的输入类型。我们将其设置为NULL,因此它变得不可编辑。
Here's the sample that might be useful (I code this on my onCreateView method Fragment):
以下是可能有用的示例(我在onCreateView方法片段中对此进行了编码):
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.yourfragment, container, false);
EditText sample = view.findViewById(R.id.youredittext);
sample.setInputType(InputType.TYPE_NULL);
Hope this will answer the problem
我希望这能解决这个问题
An easy and safe method:
一种简单安全的方法:
editText.clearFocus();
editText.setFocusable(false);
I found a way to make an uneditable editText field:
我找到了一种方法来创建一个不可编辑的编辑文本字段:
findViewById<EditText>(R.id.yourEditTextId).isEnabled = false
更多回答
The edit text will still receive key events after disable above, combine the answer with Sumit Sonome answer below to fully make it non-editable.
编辑文本在上面禁用后仍将收到关键事件,将答案与Sumit Sonome答案下面的答案结合起来,使其完全不可编辑。
This is my preferred solution, plus setInputType(InputType.TYPE_NULL)
as some other solutions also disable scrolling as well as editing
这是我的首选解决方案,外加setInputType(InputType.TYPE_NULL),因为其他一些解决方案也禁用滚动和编辑
Please provide additional details as to why this will solve the issue.
请提供更多细节,说明为什么这将解决问题。
setFocusableInTouchMode save my day! Thank you
setFocusableInTouchMode拯救我的一天!谢谢你
我是一名优秀的程序员,十分优秀!