EditTextPreference inputType = textPassword不起作用

问题描述 投票:0回答:1

我已经使用模板创建了SettingsActivity,并将EditTextPreference放入了root_preferences.xml中。它应该包含一个密码,所以我这样编辑它:

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/colorBackground">

<EditTextPreference
        android:id="@+id/etPassword"
        android:dialogTitle="Passwort"
        android:inputType="textPassword"
        android:key="pref_password"
        android:selectAllOnFocus="true"
        android:singleLine="true"
        android:title="Passwort" />

我的问题是inputType,singleLine或setAllOnFocus都不起作用。你知道出什么问题吗?

android xml preferences edittextpreference
1个回答
0
投票

您无法通过XML进行操作,但是EditTextpreference公开了EditText,因此您可以通过编程方式进行操作。在“活动/片段”中加载首选项后,您可以执行以下操作:

   EditTextPreference pref = (EditTextPreference) 
   PreferenceManager.findPreference("edit");  
   EditText prefEditText = pref.getEditText();
   prefEditText.setInputType(InputType.TYPE_CLASS_TEXT); // set properties here
   prefEditText.setSingleLine(true);
© www.soinside.com 2019 - 2024. All rights reserved.