共享首选项中的 Android 颜色 [英] Android colors in sharedpreferences

查看:53
本文介绍了共享首选项中的 Android 颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序中是 settings_activity ,人们可以在其中更改某些颜色(图标、文本等).我想在共享首选项中添加颜色,创建类:

In my application is settings_activity where people can change some colors (icons, text etc). I want to put colors in sharedpreferences, created class:

public class AppData {
    static SharedPreferences prefdata;
    static SharedPreferences.Editor editordata;

    static final String  FCOLOR_KEY = "#FFFFFF"; //first color
    static final String SCOLOR_KEY = "#FFFFFF"; //second color
    static final String TCOLOR_KEY = "#FFFFFF"; //text color
    static final String ICOLOR_KEY = "#FFFFFF"; //icon color
    static final Image BIMG_KEY = null; //bakcground image

}

颜色的最佳值类型是什么(整数、字符串或仅颜色)?

What is best value type for colors (int, string or just colors)?

如何使用 settings_activity 更改 appdata 中的值,以及如何在 xml 文件中使用它(颜色)?我应该使用colors.xml(如何?)?

How can I change values from appdata by use settings_activity and how can I use it (colors) in xml files? Should I use colors.xml(how?)?

推荐答案

如果您要使用颜色枚举,我会使用一个 int 来存储它.(整数的数据类型见下文)

If you are going to use the color enumeration, I would just use an int to store it. (See below for data type of ints)

http://developer.android.com/reference/android/graphics/颜色.html

但是,如果您要使用十六进制值,那么我会将其存储为字符串.加载应用时,检查共享首选项并加载字符串,如果该选项不存在,则加载默认颜色.

However, if you are going to use the hexadecimal value, then I would store it as a string. When you load your app, check the shared preferences and load the string and if the option does not exist load a default color.

object.setColor(sharedPreferences.getString("COLOR", "#FFFFFF"));.

这篇关于共享首选项中的 Android 颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆