0

I am building an app that is in the Persian(Farsi) language, and of course, I need snackBar but the problem is here: Please take look at this photo, I want to set the Title on the right side of the snackBar

enter image description here

Here is my snackBar Code:

 Snackbar.make(
                mEditFragmentBiding.root,
                resources.getText(R.string.empty_user_field_error),
                Snackbar.LENGTH_LONG
            )
                .setAction(resources.getText(R.string.submit)) {
                }
                .setActionTextColor(resources.getColor(android.R.color.white))
                .show()

Actually, I have visited and checked other answers like this or this one but there weren't what I wanted.

Appreciate any help.

Amir
  • 333
  • 4
  • 16
  • Snackbars will use an RTL layout when the app supports it - the rest of your UI isn't RTL either (the toolbar isn't mirrored) so you probably haven't set it up. Take a look here: https://developer.android.com/training/basics/supporting-devices/languages#SupportLayoutMirroring – cactustictacs Oct 21 '21 at 18:11
  • Thanks that was what I looked for before, but I have a question and my question is: Is it possible to configure it in some fragments using left to right(normal English) and some other fragments right to left(Persian)? – Amir Oct 21 '21 at 19:28
  • I mean is it possible to disable this property in some cases(some Buttons and TextViews)? – Amir Oct 21 '21 at 19:54
  • I think you can find the answer in here: https://stackoverflow.com/questions/35251791/right-to-left-snackbar – daniyelp Oct 21 '21 at 20:37
  • 1
    If it's for specific widgets, you could try the ``layoutDirection`` and ``textDirection`` XML properties, and force them to ``ltr``. If it's for entire fragments, you'd probably have to change the ``context`` (like in this example: https://github.com/PhraseApp-Blog/phrase-android-i18n-tutorial/blob/main/app/src/main/java/com/phrase/android/wx/utils/LocaleUtils.kt - see how they're changing the locale and layout direction) but I don't know anything about where you'd set that in a Fragment, I haven't done it before. Maybe something to look into! – cactustictacs Oct 21 '21 at 21:31
  • Thanks a million – Amir Oct 21 '21 at 22:20

1 Answers1

0

Here is the link to the tutorial that those people whose language is Persian(right to left)need.

and if you want not to change the posion of some objects like TextViews you have to add this line in Xml of your object or layout.

 android:layoutDirection="ltr"
 android:gravity="right"

for instense:

  <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="30dp"
        android:layoutDirection="ltr"
        android:gravity="right"
        android:onClick="@{() -> viewModel.goToIncrease()}"
        android:orientation="horizontal">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginEnd="8dp"
            android:gravity="center"
            android:textColor="@color/black"
            android:textSize="20sp" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginEnd="8dp"
            android:gravity="center"
            android:text="@string/submit_increase"
            android:textColor="@color/black"
            android:textSize="20sp" />
        
        <ImageView
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_gravity="left"
            android:src="@drawable/ic_baseline_add_circle_24" />
    </LinearLayout>

just look at linear layout and you will figher out how to use(I said it for BEGINERES).

Amir
  • 333
  • 4
  • 16