在我的应用程序中是settings_activity,人们可以在其中更改一些颜色(图标、文本等)。我想将颜色放在共享首选项中,创建的类中:
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
}
颜色的最佳值类型是什么(整数、字符串或只是颜色)?
如何使用 settings_activity 更改 appdata 中的值以及如何在 xml 文件中使用它(颜色)?我应该使用colors.xml(如何?)?
如果您要使用颜色枚举,我会使用 int 来存储它。 (int的数据类型见下文)
http://developer.android.com/reference/android/graphics/Color.html http://developer.android.com/reference/android/graphics/Color.html
但是,如果您要使用十六进制值,那么我会将其存储为字符串。加载应用程序时,检查共享首选项并加载字符串,如果该选项不存在,则加载默认颜色。
object.setColor(sharedPreferences.getString("COLOR", "#FFFFFF"));.
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)