Search code examples
androidandroid-snackbar

When I Try to Change the Color of SnackBar TextView App Crashes


the error in 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>

and code :

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

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

Solution

  • Try this,

    You need to pass view of SnackBar to find the textView of 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));