I am trying to change the color of the background app when I click a menu for example change background black. The color it is changing for the first time into transparent so like grey and than stays blue.
I want if the color is red to take red and other colors. This is my code.
mPopupMenu = new PopupMenu(this, settings);
MenuInflater menuInflater = mPopupMenu.getMenuInflater();
menuInflater.inflate(R.menu.main_settings, mPopupMenu.getMenu());
settings.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mPopupMenu.show();
mPopupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
int id = item.getItemId();
if(id == R.id.menu_back_white) {
setActivityBackgroundColor(R.color.white);
} else if (id == R.id.menu_back_black) {
setActivityBackgroundColor(R.color.material_grey_900);
}
return false;
}
});
}
});
public void setActivityBackgroundColor(int color) {
View view = this.getWindow().getDecorView();
view.setBackgroundColor(color);
}
colors
<color name="material_grey_900">#ff212121</color>
<color name="white">#FFFFFF</color>
styles
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimaryDark">@color/blue_900</item>
<item name="colorPrimary">@color/blue_300</item>
<item name="colorAccent">@color/blue_300</item>
<item name="colorControlNormal">@color/white</item>
</style>