android search icon,Android SearchView - Move icon to right (without ActionBar)
时间: 2023-06-17 15:08:50 浏览: 137
解决Android SearchView不显示搜索icon的问题
To move the search icon to the right in a SearchView without an ActionBar, you can use a custom layout for the SearchView. Here is an example code snippet:
```xml
<androidx.appcompat.widget.SearchView
android:id="@+id/search_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false"
android:queryHint="Search"
app:iconifiedByDefault="false"
app:queryHint="Search">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="end"
android:orientation="horizontal">
<ImageView
android:id="@+id/search_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_search_black_24dp" />
<EditText
android:id="@+id/search_src_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@null"
android:hint="Search"
android:inputType="text"
android:maxLines="1"
android:textColor="@android:color/black"
android:textSize="16sp" />
</LinearLayout>
</androidx.appcompat.widget.SearchView>
```
In this layout, the search icon is placed in an ImageView inside a LinearLayout that is set to gravity "end" (right). The EditText containing the search query text is also placed inside the same LinearLayout so that it appears to the left of the search icon. You can customize the layout further to suit your needs.
阅读全文