Android Snackbar TextAlignment in Center

前端 未结 6 1904
误落风尘
误落风尘 2021-02-18 13:30

How to change the Snackbar text alignment to center ? bellow code is not working

Snackbar snack = Snackbar.make(findViewById(android.R.id.content), in         


        
6条回答
  •  醉话见心
    2021-02-18 14:02

    The code below does the trick for me:

    TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text);
    if(tv!=null) {
       if (Build.VERSION.SDK_INT > Build.VERSION_CODES.JELLY_BEAN)
           tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER);
    
       tv.setGravity(Gravity.CENTER_HORIZONTAL);
    }
    

提交回复
热议问题