How to set support library snackbar text color to something other than android:textColor?

前端 未结 22 2355
温柔的废话
温柔的废话 2021-01-30 12:33

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

22条回答
  •  不思量自难忘°
    2021-01-30 12:59

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

提交回复
热议问题