Android使用SharedPreferences实现本地轻量存储,ToggleButton,TextView边框详解

来源:互联网 发布:产品在淘宝没有展现 编辑:程序博客网 时间:2024/06/10 05:03

工作内容:

1.使用轻量级存储方式,将设置存储到本地SharedPreferences。

注意:

SharedPreferences.editor editor = sharedPreferences.edit();

editor.clear();//存储时使用,可防止重复存储时,存储失败等等错误

edit.putInt(....)

2.ToggleButton的使用。

3.TextView【组件边框详解】

学习分享:

给组件添加边框(设置圆角)

Corners——radius设置圆角的度。【没有则表示直角边框】

Solid——color填充背景色。

Stroke——width设置边框的厚度。

Gradient——endColor渐变最后颜色。

Item——bottom去掉下边框的厚度(抵消在stroke中设置的width)。


SharedPreferencesd的使用

import android.content.Context;import android.content.SharedPreferences;
public class SharedpreferenceUtil {    private static SharedPreferences sharedPreferences = null;    private static final String DATAKEY = "DATAKEY"; //是自定义的一个常量(sharedPreferences在本地存储文件的名称)    private static final String startKey = "startKey", notifyKey = "notifyKey";    /**     * 将设置写入本地DATAKEY.xml(所在位置:data/data/+context.getPackageName+/shared-prefs/DATAKEY.xml)     *     * @param context 上下文     * @param isStart 存储的数据     */    public static void writeSet_start(Context context, int isStart) {        if (sharedPreferences == null) {            /**             * 得到SharedPreferences的一个实现类的对象             * context.MODE_PRIVATE 是一个int型的数据表示sharedPreferences的类型             */            sharedPreferences = context.getSharedPreferences(DATAKEY, context.MODE_PRIVATE);        }        //获取一个编辑器Editor对象        SharedPreferences.Editor editor = sharedPreferences.edit();        /**         * 将设置写入本地文件         * startKey 是存取的钥匙(取数据的时候用它去取到相应的存储值)         */        editor.putInt(startKey, isStart);        editor.commit();    }    //获取本地sharedPreferences的xml文件里存储的设置信息    public static int getSet_start(Context context) {        if (sharedPreferences == null) {            sharedPreferences = context.getSharedPreferences(DATAKEY, context.MODE_PRIVATE);        }        //获取startKey对应的值        return sharedPreferences.getInt(startKey, -1);    }}


0 0