首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >EditTextPreference即使使用android:inputType="textPassword“也不隐藏密码。

EditTextPreference即使使用android:inputType="textPassword“也不隐藏密码。
EN

Stack Overflow用户
提问于 2019-07-13 11:45:46
回答 1查看 2K关注 0票数 7

我有以下代码

代码语言:javascript
运行
复制
<androidx.preference.PreferenceScreen xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:android="http://schemas.android.com/apk/res/android">

        <EditTextPreference
            app:key="pref_password"
            app:title="Password"
            app:iconSpaceReserved="false"
            app:dialogTitle="Password"
            android:inputType="textPassword"/>

</androidx.preference.PreferenceScreen>

但是,即使使用android:inputType="textPassword",编辑文本字段也不会被点屏蔽。

我用的是雄激素。谁来帮帮忙

更新

我试着按照一位评论者的建议跟随,但没有运气。

代码语言:javascript
运行
复制
<EditTextPreference
            android:key="pref_password"
            android:title="Password"
            app:iconSpaceReserved="false"
            android:dialogTitle="Password"
            android:inputType="textPassword"/>
EN

Stack Overflow用户

回答已采纳

发布于 2019-07-15 01:17:21

直接在EditTextPreference上设置属性不适用于AndroidX库--因为EditTextPreference不是‘an EditText,也不应该是’EditText‘。相反,您应该使用OnBindEditTextListener来自定义显示的EditText。(需要androidx.preference:preference v1.1.0及更高版本)

有关更多信息,请参见设置指南

用代码编辑:

Java:

代码语言:javascript
运行
复制
EditTextPreference preference = findPreference("pref_password");

if (preference!= null) {
    preference.setOnBindEditTextListener(
            new EditTextPreference.OnBindEditTextListener() {
                @Override
                public void onBindEditText(@NonNull EditText editText) {
                    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                }
            });
}

Kotlin:

代码语言:javascript
运行
复制
val editTextPreference: EditTextPreference? = findPreference("pref_password")

        editTextPreference?.setOnBindEditTextListener {editText ->  
            editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_PASSWORD
        }
票数 10
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57018865

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档