【问题标题】:When I Try to Change the Color of SnackBar TextView App Crashes当我尝试更改 SnackBar TextView 应用程序崩溃的颜色时
【发布时间】:2017-10-20 14:11:38
【问题描述】:

logcat 中的错误:

10-20 13:51:31.926 12874-12874/com.project.android.tourism E/dalvikvm: Could not find class 'android.graphics.drawable.RippleDrawable', referenced from method android.support.v7.widget.AppCompatImageHelper.hasOverlappingRendering
10-20 13:51:32.110 12874-12874/com.project.android.tourism E/dalvikvm: Could not find class 'android.widget.ThemedSpinnerAdapter', referenced from method android.support.v7.widget.AppCompatSpinner$DropDownAdapter.<init>

和代码:

TextView textViewSnack = (TextView) findViewById(android.support.design.R.id.snackbar_text);   

textViewSnack.setTextColor(ContextCompat.getColor(PlaceActivity.this, R.color.colorPrimaryDark));

【问题讨论】:

    标签: android android-snackbar


    【解决方案1】:

    试试这个,

    你需要通过SnackBarview找到SnackBartextView

    Snackbar snackbar = Snackbar.make(
                        coordinatorLayout,
                        "Snackbar: floatingActionButton1 (normal) clicked",
                        Snackbar.LENGTH_LONG);
    snackbar.setActionTextColor(Color.RED); //to change the color of action text
    View snackbarView = snackbar.getView();
    snackbarView.setBackgroundColor(Color.WHITE);
    TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text);
    textView.setTextColor(ContextCompat.getColor(PlaceActivity.this, R.color.colorPrimaryDark));
    

    【讨论】:

    • 谢谢你回答我。但我的代码完全一样,首先我得到了snackbar的视图并尝试像你一样改变textview的属性
    • 但是看看你的代码你没有提到snackbar.findviewbyid
    • 你能在你的问题中再次发布你的完整代码吗
    • 谢谢你,伙计,是的,我忘记了那部分。我现在改了,运行完美,非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-07
    相关资源
    最近更新 更多