Android preferences spinner

别等时光非礼了梦想. 提交于 2019-12-12 07:15:56

问题


How can I build something like this? I wanna open a dialog in the Preferences Activity, where the user can change the number with a spinner, when he clicks on the according preference item.

I got the screenshot from Android Developer Tools, but I cannot find some example code.


回答1:


I have developed a Custom Preference, which can be found here.

XML Code:

<com.vanniktech.vntnumberpickerpreference.VNTNumberPickerPreference
    android:defaultValue="@integer/font_size_default_value"
    android:key="preference_font_size"
    android:title="@string/font_size"
    app:vnt_maxValue="@integer/font_size_max_value"
    app:vnt_minValue="@integer/font_size_min_value" />

Gradle include:

compile 'com.vanniktech:vntnumberpickerpreference:1.0.0'



回答2:


Launch the Spinner/picker in the preference's event handler:

final EditTextPreference msgLimitPref = (EditTextPreference)
                                 findPreference("prefMsgLimit");
                         msgLimitPref.setOnPreferenceClickListener(new
                                 OnPreferenceClickListener() {
                                 @Override
                                public boolean onPreferenceClick(Preference preference) {
                                     msgLimitPref.getDialog().dismiss();
                                   //launch spinner/numberpicker/activity/dialog here
                                 return true;
                                 }
                                 });


来源:https://stackoverflow.com/questions/24508155/android-preferences-spinner

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!