如何在 Android Studio 中更改 Snackbar 背景文本颜色?
我的 Snackbar 背景显示我在 Theme.xml 上设置的默认背景。那么,如何更改 SnackBar 的背景颜色呢?
任何帮助将不胜感激。
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();
}
});
}
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.
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能需要尝试
message.setBackgroundColor(colorYouWant)
。另外,如果您有colors.xml,我会说要确保您正确命名颜色。
如需了解更多信息,您还可以查看此答案。
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.