【问题标题】:Snack bar from right to left(custom snackBar) Kotlin小吃吧从右到左(自定义snackBar) Kotlin
【发布时间】:2021-12-08 10:58:45
【问题描述】:

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

这是我的零食条码:

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

实际上,我已经访问并检查了其他答案,例如 this this one,但没有我想要的。

感谢任何帮助。

【问题讨论】:

  • Snackbars 将在应用程序支持时使用 RTL 布局 - 您的 UI 的其余部分也不是 RTL(工具栏未镜像),因此您可能尚未设置它。看这里:developer.android.com/training/basics/supporting-devices/…
  • 谢谢这是我之前寻找的,但我有一个问题,我的问题是:是否可以使用从左到右(普通英语)和其他一些片段在某些片段中配置它左(波斯语)?
  • 我的意思是在某些情况下(某些按钮和文本视图)是否可以禁用此属性?
  • 我想你可以在这里找到答案:stackoverflow.com/questions/35251791/right-to-left-snackbar
  • 如果是针对特定的小部件,您可以尝试layoutDirectiontextDirection XML 属性,并将它们强制为ltr。如果是针对整个片段,您可能必须更改 context(例如在此示例中:github.com/PhraseApp-Blog/phrase-android-i18n-tutorial/blob/… - 看看他们如何更改语言环境和布局方向)但我不知道您在哪里d 将它设置在一个片段中,我以前没有这样做过。也许需要调查一下!

标签: android kotlin right-to-left android-snackbar


【解决方案1】:

Here is the link to the tutorial那些语言是波斯语(从右到左)的人需要。

如果您不想更改某些对象(例如 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)。

【讨论】:

    猜你喜欢
    • 2016-05-17
    • 2019-07-25
    • 2017-12-14
    • 2020-09-07
    • 2018-07-03
    • 2020-02-20
    • 2020-10-18
    • 2020-10-29
    • 2015-02-13
    相关资源
    最近更新 更多