如何通过编程将android主题更改为snackbar?

如何通过编程将android主题更改为snackbar?,android,styles,themes,snackbar,Android,Styles,Themes,Snackbar,我想更改我的自定义snackbar的主题 public class CustomSnackbar extends BaseTransientBottomBar<CustomSnackbar> { public CustomSnackbar( CoordinatorLayout parent, View contentView, BaseTransientBottomBar.ContentViewCallback contentViewCallb

我想更改我的自定义snackbar的主题

public class CustomSnackbar extends BaseTransientBottomBar<CustomSnackbar> {
  public CustomSnackbar(
      CoordinatorLayout parent,
      View contentView,
      BaseTransientBottomBar.ContentViewCallback contentViewCallback) {
    super(parent, contentView, contentViewCallback);
  }
我试图从语法上设置主题,但没有找到对应的主题:


缺少
contentView.setTheme
。不是每个xml属性都可以通过代码设置吗?

如果您使用的是LayoutInflater,那么您必须用xml设置主题

如果以编程方式创建视图:

View contentView = new View(context);
然后稍微改变一下:

View contentView = new View(new ContextThemeWrapper(context, R.style.Theme_my_WithDarkTextButton);

您不能按需设置主题。视图仅在构造时读取主题属性。

您只能在构造时将主题设置为视图构造函数的第三个参数(
defstylettr
)。您传递的内容是什么?
contentView
?不是。有很多只是XML或构造函数。
View contentView = new View(new ContextThemeWrapper(context, R.style.Theme_my_WithDarkTextButton);