【问题标题】:Search View: Setting the hint Icon to the right outside of a toolbar搜索视图:将提示图标设置在工具栏的右侧
【发布时间】:2021-01-27 20:44:58
【问题描述】:

我通过使用将搜索视图默认搜索图标设置在右侧

 android:layoutDirection="rtl"

但是在我的用例中,我必须默认显示搜索查询提示,我使用的是

     app:iconifiedByDefault="false"

但是,在查询提示中,搜索图标会跳回左侧。有谁知道如何将查询提示搜索图标设置在右侧。此搜索视图不在应用工具栏中。

【问题讨论】:

    标签: android android-layout searchview


    【解决方案1】:

    我发现,如果您通过 android:queryHint 提供的文本是 RTL 语言,它可以正常工作。例如,在希伯来语中:

    <SearchView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layoutDirection="rtl"
        app:iconifiedByDefault="false"
        android:queryHint="רמז"/>
    

    不幸的是,我找不到任何技巧让它与 LTR 语言一起工作。

    【讨论】:

      【解决方案2】:

      添加textDirection

      <androidx.appcompat.widget.SearchView
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:layoutDirection="rtl"
              android:textDirection="rtl"
              app:iconifiedByDefault="false"
              app:queryHint="ABC"/> 
      

      或者只是创建EditText

      <EditText
              android:layout_width="match_parent"
              android:layout_height="wrap_content"
              android:gravity="end"
              android:hint="ABC"
              android:drawablePadding="8dp"
              android:drawableEnd="@android:drawable/ic_menu_search" />
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-04-09
        • 1970-01-01
        • 1970-01-01
        • 2018-05-02
        • 2016-10-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多