Right To Left SnackBar
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
https://github.com/semsamot/ActionBarRTLizer.git
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();
I solved this problem by set custom layout for snack layout according to this refrence.
customize snackBar's layout
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);