我们可以在不可编辑的EditText文本 [英] Can we have uneditable text in edittext

查看:94
本文介绍了我们可以在不可编辑的EditText文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是的EditText 。是否有可能有文字的不可编辑的其余部分可编辑的一个组成部分,同样的EditText

I am using an EditText. Is it possible to have a part of text uneditable and the rest editable in the same EditText?

推荐答案

您可以使用

editText.setFocusable(false);

editText.setEnabled(false);

虽然禁用的EditText 当前不忽略屏幕上的键盘(我认为这是一个错误)。

although disabling the EditText does currently not ignore input from the on-screen keyboard (I think that's a bug).

根据应用的不同,可能会更好使用<一个href="http://developer.android.com/reference/android/text/InputFilter.html"><$c$c>InputFilter一个拒绝所有更改:

Depending on the application it might be better to use an InputFilter that rejects all changes:

editText.setFilters(new InputFilter[] {
    new InputFilter() {
    	public CharSequence filter(CharSequence src, int start,
    		int end, Spanned dst, int dstart, int dend) {
    		return src.length() < 1 ? dst.subSequence(dstart, dend) : "";
    	}
    }
});

另请参见<一href="http://stackoverflow.com/questions/660151/how-to-replicate-androideditablefalse-in-$c$c">this的问题。

这篇关于我们可以在不可编辑的EditText文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆