Search code examples
androidkotlinright-to-leftandroid-snackbar

Snack bar from right to left(custom snackBar) Kotlin


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.


Solution

  • 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).