【问题标题】:What's wrong with my Snackbar?我的 Snackbar 怎么了?
【发布时间】:2016-04-17 21:25:22
【问题描述】:

我的 Snackbar 出了什么问题?我刚刚尝试使用 RED SnackBar,但出现了问题,它的颜色不是红色...这是我的小吃店代码和图像,以显示我尝试设置的颜色和颜色...请帮助我!

public void processException (String exceptionMessage) {
        Snackbar snackbar = Snackbar.make(getActivityContent(), exceptionMessage, Snackbar.LENGTH_LONG);
        View snackBarView = snackbar.getView();
        snackBarView.setBackgroundColor(R.color.red);
        snackbar.show();
}

My snackbar

【问题讨论】:

    标签: android android-snackbar


    【解决方案1】:

    setBackgroundColor有问题,不能只输入颜色的id,需要实际返回你要设置的颜色的值,所以:

    snackBarView.setBackgroundColor(ContextCompat.getColor(this, R.color.red));
    

    【讨论】:

      【解决方案2】:

      在 setBackgroundColor() 中你应该传递颜色值而不是 id

      snackBarView.setBackgroundColor(ContextCompat.getColor(YourActivity.this, R.color.red));

      【讨论】:

        猜你喜欢
        • 2012-09-05
        • 2017-09-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多