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:

- 1,526
- 3
- 20
- 30
6 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);

- 1,526
- 3
- 20
- 30
-
1Use ViewCompat from android.support.v4.view.ViewCompat for android below 17 As in https://stackoverflow.com/questions/30463608/set-layoutdirection-rtl-for-api-lower-than-17/37670836. – M at Dec 14 '17 at 13:08
-
simple and useful – taha May 22 '19 at 06:50
-
You save my day ;) – Milad Faridnia Jun 08 '22 at 08:51
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();

- 155
- 2
- 6
-
Ok, But its useful while you want to use RTL direction for your app. In some cases you want to use LTR direction for the app and RTL for some widgets. – Seyyed Jan 10 '17 at 12:58
you have to set this based on Local. Android supports this feature.
From Android API Level 17+ it supports RTL natively. To force your entire layout to be RTL including the ActionBar do the following.
In Android manifest under the application tag keep this
android:supportsRtl="true"
defince a method like this in Utils class
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static void getRtlSupport() {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1){
getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
}
Use this repo as reference and implement this for snackbar

- 2,632
- 1
- 24
- 30
-
-
this is not the best practice. better way for avoiding something strange happen to RTL language Lovers in android app development is create custom RTL layout and inflate that on every where across app e.g. toolbar with custom RTL layout has better performance in each API than choose Android RTL Support and force the layout to be RTL. so this is my experience. thanks patient reader – Setmax Oct 01 '16 at 09:00
I solved this problem by set custom layout for snack layout according to this refrence.

- 1
- 1

- 973
- 1
- 12
- 24
private void showSnackbar(String text, int Length, String Action, View.OnClickListener clickListener) {
Snackbar snackbar = Snackbar.make(findViewById(R.id.coordinatorLayout), text, Length);
View snack = snackbar.getView();
snackbar.getView().setRotationY(180);
snack.setBackgroundColor(getResources().getColor(R.color.DarkBlue));
TextView snack_text = (TextView)snack.findViewById(android.support.design.R.id.snackbar_text);
TextView snack_action = (TextView)snack.findViewById(android.support.design.R.id.snackbar_action);
snack_text.setTypeface(tf);
snack_action.setTypeface(tf);
snack_action.setRotationY(180);
snack_text.setRotationY(180);
snackbar.setAction(Action, clickListener);
snackbar.setActionTextColor(Color.parseColor("#00c4ff"));
snackbar.show();
}
-
Please explain how and why your code solves the problem, because code-only answers are not appreciated at StackOverflow. Also, you could explain, why your answer exceeds the previous older answers (mainly the accepted one). – Lukas Körfer Apr 05 '17 at 21:45
Only you need:
Snackbar snackbar=Snackbar.make(v, "آیا از حذف کامل این مورد مطمئن هستید؟", Snackbar.LENGTH_LONG)
.setAction("حذف", new View.OnClickListener() {
@Override
public void onClick(View v) {
//info@giran.ir
//09155336168
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
View snack = snackbar.getView();
snack.setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
}
snackbar.show();

- 5
- 3