我想在editText中有一个常量文本,如:
http://<here_user_can_write>
Run Code Online (Sandbox Code Playgroud)
用户不应该从" http://" 删除任何字符,我搜索了这个并发现了这个:
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) : "";
}
}
});
Run Code Online (Sandbox Code Playgroud)
但我不知道它是否限制用户不从开始到结束限制删除任何字符.我也无法理解Spanned类的使用.
一种方法是一个很好的选择,如果我们可以放入TextView内部,EditText但我不认为这是可能的Android,因为两者都是视图,是否可能?
我正在创建一个电子邮件表单,并希望在 EditText 中包含无法删除的文本。在下面的屏幕截图中,To无法删除。

如果有人对如何实现上述目标有建议,那就太好了 - 谢谢。
我当前的 EditText 框代码To:
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="0dp"
android:hint="@string/email_to" >
</EditText>
Run Code Online (Sandbox Code Playgroud)
问题是android:hint当用户开始发短信时,文本会消失,并且android:text可以被用户删除。
怎样才能有无法删除的文字呢?谢谢。
另外,我想指出,我有一种使用清除按钮清除文本的方法 - 这工作正常 - 但我希望它不会删除固定文本(如果我实现了!)..这是代码:
private void clearForm(ViewGroup group)
{
for (int i = 0, count = group.getChildCount(); i < count; ++i) {
View view = group.getChildAt(i);
if (view instanceof EditText) {
((EditText)view).setText("");
}
if(view instanceof ViewGroup && (((ViewGroup)view).getChildCount() > 0))
clearForm((ViewGroup)view);
}
}
Run Code Online (Sandbox Code Playgroud)
管理了一种迂回的方式来做到这一点。我在嵌套的线性布局中创建了一个 TextView 和 EditText。我使用 …