项目场景:
安卓开发一个模块中的编辑框需要不可编辑
问题描述
android:editable=“false”. 发现已被弃用(但仍能使用)
EditText在xml中配置inputType = “none”,依旧能编辑
官方文档描述:没有内容类型。文本不可编辑。
<EditText
android:id="@+id/ed_choose"
android:layout_width="wrap_content"
android:layout_height="@dimen/return_on_ed_height"
android:background="@drawable/no_edit_background"
android:ems="10"
android:inputType="none" />
解决方案:
- 通过代码设置
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_return_on);
// 访问编辑框
EditText ed_choose = findViewById(R.id.ed_choose);
// 设置拣选位 文本编辑框不可编辑
ed_choose.setInputType(InputType.TYPE_NULL);
}
2.通过xml设置通过使用可聚焦
<EditText
android:focusable="false"
</>