Style SnackBar in theme app

前端 未结 5 1671
深忆病人
深忆病人 2020-12-01 16:10

I need help. How can I change the design of the text in snackbar in styles app? The change in the code does not interest me. I found the following code. But it is not worki

5条回答
  •  囚心锁ツ
    2020-12-01 16:25

    Thanks to shadowsheep I wrote these styles with Material Components. I also removed margins. You can compile his app to research Snackbar.

    
    
    
    
    
    
    
    
    

    Where drawable/snackbar_background.xml is:

    
    
        
    
    

    Don't forget to remove from Snackbar.make(), if you have added:

    view.setBackgroundColor(ContextCompat.getColor(context, R.color.bg_color))
    setActionTextColor(ContextCompat.getColor(context, R.color.button_color))
    

    Unlike AlertDialog, Snackbar holds snackbarButtonStyle and snackbarTextViewStyle settings inside AppTheme (that's strange because yesterday they worked well inside MaterialSnackbarTheme).

    As @StayCool said in comments, Snackbar currently uses transparency for background and text color (alpha = 0.5 - 0.6). Also they added round corners and margins. To remove background transparency, use either 1.0 or drawable/snackbar_background.xml. You can see his variant.

提交回复
热议问题