So I\'ve started using the new Snackbar in the Design Support Library, but I found that when you define \"android:textColor\" in your theme, it applies to the text color of the
I have a simple code that will help to get an instance of both the textview of Snackbar, after that you can call all methods that are applicable on a textview.
Snackbar snackbar = Snackbar.make( ... ) // Create Snack bar
snackbar.setActionTextColor(getResources().getColor(R.color.white)); //if you directly want to apply the color to Action Text
TextView snackbarActionTextView = (TextView) snackbar.getView().findViewById( android.support.design.R.id.snackbar_action );
snackbarActionTextView.setTextColor(Color.RED); //This is another way of doing it
snackbarActionTextView.setTypeface(snackbarActionTextView.getTypeface(), Typeface.BOLD);
//Below Code is to modify the Text in Snack bar
TextView snackbarTextView = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
snackbarTextView.setTextSize( 16 );
snackbarTextView.setTextColor(getResources().getColor(R.color.white));
You can use this library: https://github.com/SandroMachado/restaurant
new Restaurant(MainActivity.this, "Snackbar with custom text color", Snackbar.LENGTH_LONG)
.setTextColor(Color.GREEN)
.show();
Disclaimer: I made the library.
If you migrated to androidX use com.google.android.material.R.id.snackbar_text
instead of
android.support.design.R.id.snackbar_text
for changing color of text on snackbar.
If you are in Kotlin, you can create an extension :
fun Snackbar.withTextColor(color: Int): Snackbar {
val tv = this.view.findViewById(android.support.design.R.id.snackbar_text) as TextView
tv.setTextColor(color)
return this
}
Usage :
yourSnackBar.withTextColor(Color.WHITE).show()