Android Settings中显示自定义dialog
生活随笔
收集整理的這篇文章主要介紹了
Android Settings中显示自定义dialog
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
第一種方法,參照NightDisplaySettings.java
@Overridepublic boolean onPreferenceTreeClick(Preference preference) {if (preference == mStartTimePreference) {showDialog(DIALOG_START_TIME);return true;return super.onPreferenceTreeClick(preference);}@Overridepublic Dialog onCreateDialog(final int dialogId) {if (dialogId == DIALOG_START_TIME || dialogId == DIALOG_END_TIME) {final Context context = getContext();final boolean use24HourFormat = android.text.format.DateFormat.is24HourFormat(context);TextView ledValueText;SeekBar ledSeekBar;View view = LayoutInflater.from(context).inflate(R.layout.led_brightness_setting_dialog, null);AlertDialog builder = new AlertDialog.Builder(context).setTitle("LED brightness setting").setView(view).create();//builder.getWindow().setContentView(R.layout.led_brightness_setting_dialog); ledValueText = (TextView) view.findViewById(R.id.led_setting_text);ledSeekBar = (SeekBar) view.findViewById(R.id.led_setting_seekbar);ledSeekBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {@Overridepublic void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {}@Overridepublic void onStartTrackingTouch(SeekBar seekBar) {}@Overridepublic void onStopTrackingTouch(SeekBar seekBar) {}});return builder;}return super.onCreateDialog(dialogId);}android8.1中繼承SettingsPreferenceFragment并在類中創(chuàng)建dialog的時候,遇到SettingsDialogFragmentjava.lang.IllegalStateException: Dialog must provide a metrics category異常。
需要override??getDialogMetricsCategory,比如:
@Overridepublic int getDialogMetricsCategory(int dialogId) {switch (dialogId) {case DIALOG_START_TIME:return MetricsEvent.DIALOG_NIGHT_DISPLAY_SET_START_TIME;case DIALOG_END_TIME:return MetricsEvent.DIALOG_NIGHT_DISPLAY_SET_END_TIME;default:return 0;}}?
轉(zhuǎn)載于:https://www.cnblogs.com/kunkka/p/10605752.html
總結(jié)
以上是生活随笔為你收集整理的Android Settings中显示自定义dialog的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 电脑PDF怎么转换成WPS,这招你学会了
- 下一篇: [01-01]oracle数据库汉化