I want to change color of navigation buttons in my application,
I tried with window.setNavigationBarColor(@ColorInt int color)
but this method changing only background of bar. Any ideas?
Step 1: After opening the android studio and creating a new project with an empty activity. Step 2: Navigate to res/values/colors. xml, and add a color that you want to change for the status bar.
You can change the navigation color dynamically using the following function. Basically it checks if the given NavigationBar background color is light or dark and sets the appropriate theme to the buttons. Setting a specific color to the buttons is not possible.
private void setNavigationBarButtonsColor(Activity activity, int navigationBarColor) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
View decorView = activity.getWindow().getDecorView();
int flags = decorView.getSystemUiVisibility();
if (isColorLight(navigationBarColor)) {
flags |= View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
} else {
flags &= ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR;
}
decorView.setSystemUiVisibility(flags);
}
}
private boolean isColorLight(int color) {
double darkness = 1 - (0.299 * Color.red(color) + 0.587 * Color.green(color) + 0.114 * Color.blue(color)) / 255;
return darkness < 0.5;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With