当我尝试更改SnackBar TextView应用程序崩溃的颜色时

时间:2017-10-20 14:11:39

标签: android android-snackbar

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));

1 个答案:

答案 0 :(得分:1)

试试这个,

您需要通过 view SnackBar来查找 textView SnackBar

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));