android PreferenceActivity 配置Activity
16lz
2021-01-23
首先创建/res/xml/settings.xml
<?xml version="1.0" encoding="utf-8"?><PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" > <CheckBoxPreference android:defaultValue="true" android:key="@string/cbp_push_notification" android:summaryOff="关闭推送通知" android:summaryOn="启动推送通知" android:title="推送通知" /> <CheckBoxPreference android:defaultValue="true" android:dependency="@string/cbp_push_notification" android:key="@string/cbp_push_sound" android:summaryOff="关闭声音" android:summaryOn="开启声音" android:title="推送声音" /> <CheckBoxPreference android:defaultValue="true" android:dependency="@string/cbp_push_notification" android:key="@string/cbp_push_vibrate" android:summaryOff="关闭震动" android:summaryOn="开启震动" android:title="推送震动" /></PreferenceScreen>然后在PreferenceActivity里添加该资源
public class NotificationSettingsActivity extends PreferenceActivity {@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);addPreferencesFromResource(R.xml.settings);}}
使用该配置要调用
SharedPreferences defaultSp = PreferenceManager.getDefaultSharedPreferences(context);return defaultSp.getBoolean(context.getString(R.string.cbp_push_notification),true);
更多相关文章
- Android判断app是否打开消息通知并跳转设置
- 基于百度推送android notification的使用之合并通知栏
- Android 8.0和8.1通知栏
- android 自定义通知消息设置背景色不生效,导致部分机型显示白色字
- Android——自定义通知栏使用
- Android耳机声音自动调整
- Android通知
- Android监听系统通知
- Android消息通知