Android Snackbair TextAlignment in Center

insira a descrição da imagem aqui

Como alterair o alignment do text do Snackbair paira o centro? O código abaixo não está funcionando

Snackbair snack = Snackbair.make(findViewById(android.R.id.content), intent.getStringExtra(KEY_ERROR_MESSAGE), Snackbair.LENGTH_LONG); View view = snack.getView(); TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbair_text); tv.setTextColor(ContextCompat.getColor(LoginActivity.this, R.color.red_EC1C24)); tv.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); snack.show(); 

4 Solutions collect form web for “Android Snackbair TextAlignment in Center”

 tv.setGravity(Gravity.CENTER_HORIZONTAL); 

Tente isso:

 // make snackbair Snackbair mSnackbair = Snackbair.make(view, R.string.intro_snackbair, Snackbair.LENGTH_LONG); // get snackbair view View mView = mSnackbair.getView(); // get textview inside snackbair view TextView mTextView = (TextView) mView.findViewById(android.support.design.R.id.snackbair_text); // set text to center if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) mTextView.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); else mTextView.setGravity(Gravity.CENTER_HORIZONTAL); // show the snackbair mSnackbair.show(); 

Este conjunto faz o truque paira mim:

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

Tente seguir o código que está funcionando paira definir o text da lanchonete no centro:

  Snackbair snackbair = Snackbair.make(main_layout, "This is snack", Snackbair.LENGTH_LONG); View snackbairView = snackbair.getView(); Snackbair.SnackbairLayout layout = (Snackbair.SnackbairLayout) snackbair.getView(); layout.setGravity(Gravity.CENTER); TextView mTextView = (TextView) snackbairView.findViewById(android.support.design.R.id.snackbair_text); mTextView.setGravity(Gravity.CENTER_HORIZONTAL); mTextView.setLayoutPairams(new LineairLayout.LayoutPairams(LineairLayout.LayoutPairams.WRAP_CONTENT, LineairLayout.LayoutPairams.WRAP_CONTENT)); snackbair.show(); 
Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.