数据存储方式(SharedPreferences)

来源:互联网 发布:js防水涂料是什么 编辑:程序博客网 时间:2024/06/15 18:36

实现效果:

建布局文件:res/xml/perference.xml(xml是res下的新建包)

代码实现:

<?xml version="1.0" encoding="utf-8"?><PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">  <SwitchPreference      android:title="WLAN"      android:summaryOn="wifi已开启"      android:summaryOff="wifi已关闭"      android:icon="@android:drawable/star_big_off"      android:key="setting_SwitchPreference"  ></SwitchPreference></PreferenceScreen>




activity 
package com.example.g160628_android_15_io_sharedpreferences;import android.os.Bundle;import android.preference.PreferenceActivity;import android.support.annotation.Nullable;/** * Created by Administrator on 2017/6/23. */public class SettingActivity extends PreferenceActivity {    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {        super.onCreate(savedInstanceState);                //使用过时的方法        addPreferencesFromResource(R.xml.perference);    }}