首页 > 解决方案 > 小吃吧从右到左(自定义snackBar) Kotlin

问题描述

我正在构建一个使用波斯语(波斯语)语言的应用程序,当然,我需要snackBar,但问题出在:请看这张照片,我想在snackBar 的右侧设置标题

在此处输入图像描述

这是我的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()

实际上,我已经访问并检查了类似这个这个的其他答案,但没有我想要的。

感谢任何帮助。

标签: androidkotlinright-to-leftandroid-snackbar

解决方案


这是波斯语(从右到左)语言的人需要的教程链接。

如果您不想更改某些对象(例如 TextViews)的位置,则必须在对象或布局的 Xml 中添加此行。

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

强烈的:

  <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>

只要看看线性布局,你就会知道如何使用(我是为 BEGINERES 说的)。


推荐阅读