Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Right To Left SnackBar

Tags:

I want to display a text with an action on Design Support Library SnackBar.
My language is writen in Right-to-Left. So how can i change SnackBar text and action direction?
Something like this:

enter image description here

like image 743
Seyyed Avatar asked Feb 07 '16 09:02

Seyyed


People also ask

How do you set a snackbar position?

Snackbars should be placed at the bottom of a UI, in front of app content.

What is snackbar used for?

Snackbar in android is a new widget introduced with the Material Design library as a replacement of a Toast. Android Snackbar is light-weight widget and they are used to show messages in the bottom of the application with swiping enabled. Snackbar android widget may contain an optional action button.

What is a snackbar in UX?

Snackbars provide brief feedback about an operation through a message at the bottom of the screen. Snackbars contain a single line of text directly related to the operation performed. They may contain a text action, but no icons. Toasts (Android only) are primarily used for system messaging.

How do I move snackbar to next page?

You're using the router, you can pass the props with push. const [snackbar, setSnackbar] = useState(location. openSnackbar); You might need to add a ternary in the useState just in case.


2 Answers

Finally from the answers and more searches i found this solution:

Snackbar snackbar =     Snackbar.make(view, "My right2left text", Snackbar.LENGTH_LONG)             .setAction("Action", new View.OnClickListener() {                 @Override                 public void onClick(View view) {                 }              }); 

Set direction to Right-to-Left:

ViewCompat.setLayoutDirection(snackbar.getView(),ViewCompat.LAYOUT_DIRECTION_RTL); 

Don't forget this for showing the snackbar:

snackbar.show(); 

UPDATE

Since you have Text and Action as TextView you can use the other TextView methods for them. like as setTypeface(), setTextSize() and so on.

Set typeface for text:

TextView text = snackbar.getView().findViewById(android.support.design.R.id.snackbar_text); text.setTypeface(yourTypeface); 

Set typeface for action:

TextView action = snackbar.getView().findViewById(android.support.design.R.id.snackbar_action); action.setTypeface(yourTypeface); 
like image 103
Seyyed Avatar answered Sep 23 '22 02:09

Seyyed


just add this codes :

In Android manifest under the application tag keep this

android:supportsRtl="true"

and this :

Snackbar snackbar = Snackbar.make(getView(), "Text", Snackbar.LENGTH_SHORT);  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {     TextView view1 = (TextView)snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);     view1.setLayoutDirection(View.LAYOUT_DIRECTION_RTL); }  snackbar.show(); 
like image 39
Ali Edp Avatar answered Sep 23 '22 02:09

Ali Edp