问题
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