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:
Snackbars should be placed at the bottom of a UI, in front of app content.
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.
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.
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.
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);
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();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With