Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom theme interferes with snackbar background color

Trying out the new Design Support Library, I added a snackbar; but unlike its main background, the text area is not colored with the default value of #323232. Instead, it looks like this. It seems to take its color from the android:background value defined in the custom theme in my styles.xml, which goes like this:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    ...
    <item name="android:background">#4f4f5e</item>
    ...
</style>

If I try to forcefully color it with

View snackbarView = snackbar.getView(); 
snackbarView.setBackgroundColor(Color.YELLOW);

it only impacts the main background, like this, and the text background still gets colored by the custom theme. Is there a way to both keep my custom theme, and have a standard snackbar? Thanks!

like image 619
Kuboå Avatar asked Jun 26 '15 13:06

Kuboå


People also ask

How do I change the background color in snackbar MUI?

Answers 1 : of Set the background color of a Snackbar in MUI With material-ui 1.0 (or higher) you should override the root CSS class from the SnackbarContent component with the prop ContentProps.

What is a snackbar in Android?

Snackbars provide lightweight feedback about an operation. They show a brief message at the bottom of the screen on mobile and lower left on larger devices. Snackbars appear above all other elements on screen and only one can be displayed at a time.


1 Answers

To change the Snackbar's background colour you can do the following from code:

Snackbar snack = Snackbar.make(...);
ViewGroup group = (ViewGroup) snack.getView();
group.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.red));
snack.show();

Instead of red you can use the Snackbar's default colour: #323232

like image 98
agirardello Avatar answered Sep 20 '22 03:09

agirardello