If you want to change the entire dialog, perhaps to use a replacement dialog box library such as material-dialogs , you can use this ListPreference replacement:
import com.afollestad.materialdialogs.MaterialDialog; public class MaterialListPreference extends ListPreference { private MaterialDialog.Builder mBuilder; private Context context; public MaterialListPreference(Context context) { super(context); this.context = context; } public MaterialListPreference(Context context, AttributeSet attrs) { super(context, attrs); this.context = context; } @Override protected void showDialog(Bundle state) { mBuilder = new MaterialDialog.Builder(context); mBuilder.title(getTitle()); mBuilder.icon(getDialogIcon()); mBuilder.positiveText(null); mBuilder.negativeText(getNegativeButtonText()); mBuilder.items(getEntries()); mBuilder.itemsCallback(new MaterialDialog.ListCallback() { @Override public void onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) { onClick(null, DialogInterface.BUTTON_POSITIVE); dialog.dismiss(); if (which >= 0 && getEntryValues() != null) { String value = getEntryValues()[which].toString(); if (callChangeListener(value)) setValue(value); } } }); final View contentView = onCreateDialogView(); if (contentView != null) { onBindDialogView(contentView); mBuilder.customView(contentView); } else mBuilder.content(getDialogMessage()); mBuilder.show(); } }
This is not so much, only the minimum minimum for overriding the dialog box and parts of the select callback. YMMV is very small, if you choose another library of dialogs, but not too many, they tend to be more or less direct replacements for AlertDialog .
source share