Hes*_*sam 176 android android-edittext
在我的应用程序中,我有一个EditText.我希望用户只具有读访问权限而不是写访问权限.在我设置的代码中android:enabled="false"
.虽然EditText的背景变为黑暗,但当我点击它时,键盘弹出,我可以更改文本.
我该怎么办?谢谢
Jul*_*ian 229
我相信正确的是设定android:editable="false"
.
如果你想知道为什么我的链接指向属性TextView
,你的答案是因为EditText
继承自TextView
:
EditText是TextView上的薄贴面,它将自身配置为可编辑.
更新:
如下面的评论中所述,editable
不推荐使用(自API级别3以来).您应该使用inputType
(使用值none
).
小智 153
用于EditText.setFocusable(false)
禁用编辑
EditText.setFocusableInTouchMode(true)
以启用编辑;
Mak*_*lin 59
您可以尝试以下方法:
private void disableEditText(EditText editText) {
editText.setFocusable(false);
editText.setEnabled(false);
editText.setCursorVisible(false);
editText.setKeyListener(null);
editText.setBackgroundColor(Color.TRANSPARENT);
}
Run Code Online (Sandbox Code Playgroud)
启用EditText:
已禁用EditText:
它对我有用,希望它对你有所帮助.
Sam*_*mar 58
使用此选项可禁用用户输入
android:focusable="false"
Run Code Online (Sandbox Code Playgroud)
android:editable ="false"此方法已弃用.
Pha*_*inh 29
对于禁用编辑EditText
,我认为我们可以使用focusable
OR enable
但是
使用android:enabled=...
或editText.setEnabled(...)
它还将文本颜色更改EditText
为灰色.
点击它没有任何影响
使用android:focusable=...
或editText.setFocusable(false)
-editText.setFocusableInTouchMode(true)
它不会改变文本颜色EditText
当点击它突出显示EditText
底线大约几毫秒
产量
Bha*_*nki 19
正如android:editable="false"
描述的那样.您可以在EditText上使用InputType TYPE_NULL
使用这样:
editText.setInputType(InputType.TYPE_NULL);
Run Code Online (Sandbox Code Playgroud)
and*_*ain 17
由于android:editable="false"
弃用在XML
用
xml
它简单.为什么要使用更多代码
如果你想在java类中,你也可以在java类中以编程方式使用
editText.setEnabled(假);
要禁用 EditText 的功能,只需使用:
EditText.setInputType(InputType.TYPE_NULL);
Run Code Online (Sandbox Code Playgroud)
如果您想以某种方式启用它,那么您可以使用:
EditText.setInputType(InputType.TYPE_CLASS_TEXT);
Run Code Online (Sandbox Code Playgroud)
禁用焦点、单击和光标可见性对我来说很有效。
这是 XML 中的代码
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false"
android:clickable="false"
/>
Run Code Online (Sandbox Code Playgroud)
我使用谷歌新发布的材料设计库。就我而言,它在我使用 android:focusable="false" 和 android:cursorVisible="false" 时有效
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/to_time_input_layout"
app:endIconMode="custom"
app:endIconDrawable="@drawable/ic_clock"
app:endIconContentDescription="ToTime"
app:endIconTint="@color/colorAccent"
style="@style/OutlinedEditTextStyle"
android:hint="To Time">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/to_time_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="false"
android:cursorVisible="false" />
</com.google.android.material.textfield.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
在课堂下面设置属性:
editText.setFocusable(false);
editText.setEnabled(false);
Run Code Online (Sandbox Code Playgroud)
它会按您的要求顺利运行.
小智 5
这将使您的 edittext被禁用。
editText.setEnabled(false);
Run Code Online (Sandbox Code Playgroud)
通过使用这个
editText.setInputType(InputType.TYPE_NULL);
Run Code Online (Sandbox Code Playgroud)
只会让你的 Edittext不显示你的软键盘,但如果它连接到物理键盘,它会让你打字。
归档时间: |
|
查看次数: |
254891 次 |
最近记录: |