How can I change the appearance of ListPreference Dialog

前端 未结 4 430
别跟我提以往
别跟我提以往 2021-01-13 10:02

I would like to change the RadioButton that appears on ListPreference dialog for a check mark or something different, or none, is there a simple wa

4条回答
  •  走了就别回头了
    2021-01-13 10:55

    if you want java code. try to following code.

    public class SearchEngineListPreference extends ListPreference {
        private Context mContext;
        public SearchEngineListPreference(Context context) {
            super(context);
            mContext = context;
        }
    
        public SearchEngineListPreference(Context context, AttributeSet attrs) {
            super(context, attrs);
            mContext = context;
        }
    
        @SuppressWarnings("New API")
        public SearchEngineListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
            super(context, attrs, defStyleAttr);
            mContext = context;
        }
    
        @SuppressWarnings("New API")
        public SearchEngineListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
            super(context, attrs, defStyleAttr, defStyleRes);
            mContext = context;
        }
    
        @Override
        protected void onClick() {
            AlertDialog.Builder ab = new AlertDialog.Builder(mContext);
            ab.setCancelable(true);
            ab.setTitle(getTitle());
            String value = getValue();
            ab.setSingleChoiceItems(R.array.setting_entries_search_engine,
                    findIndexOfValue(value),
                    (dialog, index) -> {
                        CharSequence[] entryValues = getEntryValues();
                        if (callChangeListener(entryValues[index].toString())){
                            setValueIndex(index);
                        }
                        dialog.dismiss();
                    }).setNeutralButton(mContext.getString(R.string.dialog_button_custom),
                    (dialog, whichButton) -> {
                        dialog.dismiss();
                        showEditDialog();
                    }).setNegativeButton(mContext.getString(R.string.dialog_button_negative),
                    (dialog, whichButton) -> {
                        dialog.dismiss();
                    });
            ab.show();
        }
    
        private void showEditDialog() {
          .......
        }
    
    

提交回复
热议问题