0

My Snackbar background displays the default background I've set on the Theme.xml. So, how do I change the background color of the SnackBar?

Any help would be much appreciated.

enter image description here

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    binding = ActivityNewDeltioBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());

    SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this, getSupportFragmentManager());
    ViewPager viewPager = binding.viewPager;
    viewPager.setAdapter(sectionsPagerAdapter);
    TabLayout tabs = binding.tabs;
    tabs.setupWithViewPager(viewPager);
    FloatingActionButton fab = binding.fab;

    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar message = Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null);
            message.show();
        }
    });
}

Edit: I've also tried creating a custom style, but that didn't work as expected. It changed the color of the SnackBar sides, not the background itself... ibb.co/p1zqNqd

1 Answers1

0

You might have to try message.setBackgroundColor(colorYouWant).

Also, if you have a colors.xml, I would say to make sure that you're correctly naming the colors.

For more information, you could also check out this answer.

isherwood
  • 58,414
  • 16
  • 114
  • 157
  • 1
    Welcome. Please familiarize yourself with the post editor so you can format code and other things well. – isherwood Mar 17 '22 at 16:28
  • Also, you linked to a question. Answer URLs are on the Share button on each. – isherwood Mar 17 '22 at 16:28
  • Unfortunately, I cannot use .setBackGroundColor "Cannot resolve method 'setBackgroundColor' in 'Snackbar'". –  Mar 17 '22 at 16:31
  • I've also tried creating a custom style, but that didn't work as expected. It change the color of the SnackBar sides, not the background itself... https://ibb.co/p1zqNqd –  Mar 17 '22 at 16:35