简体   繁体   English

Android EditTextPreference禁用Dialog

[英]Android EditTextPreference disable Dialog

I want to disable(not show) the Dialog, when i click the EditTextPreference in a Preference Activity. 当我单击首选项活动中的EditTextPreference时,我想禁用(不显示)对话框。

When i click the EditTextPreference, a pop up dialog show. 当我单击EditTextPreference时,会弹出一个弹出对话框。 Now i want to disable this. 现在我想禁用它。 I try set an onclicklistener, but the dialog show same. 我尝试设置一个onclicklistener,但对话框显示相同。

public class Settings extends PreferenceActivity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);       
   EditTextPreference userName=(EditTextPreference) findPreference("prefUsername");
    userName.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference preference) {

            return false;
        }
    }); ...

I try add this to the EditTextPreference: android:clickable="false", but nothing. 我尝试将此添加到EditTextPreference:android:clickable =“false”,但没有。

Disable it. 禁用它。

Use 采用

android:enabled="false"

in XML. 在XML中。 Or to disable in runtime, 或者在运行时禁用

userName.setEnabled(false);

Actually, if you do not want a dialog, you probably should use simple Preference instead of EditTextPreference . 实际上,如果您不想要对话框,则可能应该使用简单的Preference而不是EditTextPreference

try to replace 试着替换

EditTextPreference

with

Preference

so your code will be like this 所以你的代码就是这样的

<Preference
        android:selectAllOnFocus="true"
        android:singleLine="true"
        android:title="Version "
        android:key="edit_text_preference_1"
        android:summary="1.0" 
        android:enabled="true" />

hope this help you 希望这能帮助你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 确认EditTextPreference对话框后Android软键盘保持打开状态 - Android soft keyboard stays open after confirming EditTextPreference dialog Android EditTextPreference样式 - Android EditTextPreference style 如何编辑android蜂窝中的EditTextPreference? - how to edit the EditTextPreference in android honeycomb? 更改EditTextPreference对话框输入的文本颜色 - Change EditTextPreference dialog input text color 如何在Android中禁用对话框的按钮? - How to disable button of a dialog in Android? 可以在Android中动态更改EditTextPreference的摘要吗? - Is possible to change the summary of EditTextPreference dynamically in Android? android中的SharedPreference(告诉朋友+禁用对话框通知) - SharedPreference in android(Tell friend + Disable Dialog notification) 在Android中的共享首选项中禁用对话框通知 - Disable Dialog Notification in Shared Preference in android 如何验证在Android 2.1中输入的EditTextPreference的格式和值? - How do you validate the format and values of EditTextPreference entered in Android 2.1? 如何像android:password =“ true”一样动态地将密码属性设置为EditTextPreference? - How to set password attribute to EditTextPreference dynamically like android:password=“true”?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM