Issue
Hello I'm using Shared Preferences to store colors of the APP. Until now I can save the colors of the button and status bar because they don't use drawable colors.
This is are my functions:
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;
}
And I'm using them like this:
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());
}
}
Before I was using toolbar, but now I want to use the action bar. I'm a little lost here How can I add drawable colors here?
Solution
Use a ColorDrawable.
int color = getColor();
getActionBar().setBackgroundDrawable(new ColorDrawable(color));
Answered By - Hsingchien Cheng
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.