共享首选项可绘制颜色Android
您好,我正在使用共享首选项存储应用程序的颜色。 到目前为止,我可以保存按钮和状态栏的颜色,因为它们不使用可绘制的颜色 这是我的职责:共享首选项可绘制颜色Android,android,android-actionbar,sharedpreferences,drawable,android-drawable,Android,Android Actionbar,Sharedpreferences,Drawable,Android Drawable,您好,我正在使用共享首选项存储应用程序的颜色。 到目前为止,我可以保存按钮和状态栏的颜色,因为它们不使用可绘制的颜色 这是我的职责: private void storeColor(int color){ SharedPreferences mSharedpreferences = getSharedPreferences("ToolbarColor", MODE_PRIVATE); SharedPreferences.Editor mEditor = mSharedprefer
private void storeColor(int color){
SharedPreferences mSharedpreferences = getSharedPreferences("ToolbarColor", MODE_PRIVATE);
SharedPreferences.Editor mEditor = mSharedpreferences.edit();
mEditor.putInt("color", color);
mEditor.apply();
}
private int getColor(){
SharedPreferences mSharedPreferences = getSharedPreferences("ToolbarColor", MODE_PRIVATE);
int selectedColor = mSharedPreferences.getInt("color", getResources().getColor(R.color.colorPrimary));
return selectedColor;
}
我是这样使用它们的:
if (intValue == 1){
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.green_apple));
btn_historial.setBackgroundColor(getResources().getColor(R.color.green_apple));
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(getResources().getColor(R.color.green_apple));
}
storeColor(getResources().getColor(R.color.green_apple));
}
if(getColor() != getResources().getColor(R.color.colorPrimary)){
getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.color.colorPrimary));
btn_historial.setBackgroundColor(getColor());
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().setStatusBarColor(getColor());
}
}
以前我使用工具栏,但现在我想使用操作栏。
我在这里有点不知所措,如何在这里添加可绘制的颜色?使用一种颜色
你想从共享首选项添加颜色是你的问题吗?嗯,那么,你想从共享首选项向操作栏添加背景颜色吗?您不确定如何在sharepreference中保存可绘制的吗?@ArpitPatel是将您的六位代码保存为首选项中的字符串,并使用like Color进行设置。parseColor(首选项值)@ArpitPatel如何做到这一点?当我打印行时,它会显示new bgColorKey=android.graphics.drawable。ColorDrawable@91cdd14它不读取解析的十六进制值,可能更好
Color.parseColor(Color)代码>@marlonpya我想它说的是整数颜色<代码>颜色。解析颜色(颜色)代码>表示字符串。
int color = getColor();
getActionBar().setBackgroundDrawable(new ColorDrawable(color));