How to programmatically change the radiobutton
color which is inside the popupmenu
private void showPopupMenu(View view) {
PopupMenu popupMenu = new PopupMenu(getContext(), view);
popupMenu.getMenuInflater().inflate(R.menu.menu_publish_more_popup, popupMenu.getMenu());
MenuItem postItem = popupMenu.getMenu().findItem(R.id.action_post);
postItem.setChecked(true);
RadioButton radioButton = (RadioButton) (postItem.getActionView());
if (Build.VERSION.SDK_INT >= 21) {
ColorStateList colorStateList = new ColorStateList(
new int[][]{
new int[]{-android.R.attr.state_enabled}, //disabled
new int[]{android.R.attr.state_enabled} //enabled
},
new int[]{
Color.GREEN
, Color.RED
}
);
radioButton.setButtonTintList(colorStateList);//set the color tint list
radioButton.invalidate(); //could not be necessary
}
popupMenu.show();
}