![](/img/trans.png)
[英]How do i make the search icon in the SearchView widget to align to the right end of the layout?
[英]Searchview widget : move search icon to right
我有这个searchView,我想将搜索图标移到右边(如果可能的话)
我的xml代码:
<android.widget.SearchView
android:id="@+id/searchBox"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="7dp"
android:layout_below="@+id/header"
android:iconifiedByDefault="false"
android:background="@drawable/searchrectangle"
android:queryHint="@string/search_message">
</android.widget.SearchView>
如果我是正确的,这是searchview的来源https://android.googlesource.com/platform/frameworks/support.git/+/jb-mr2-release/v7/appcompat/res/layout/abc_search_view.xml 。
从它的外观来看,它使用线性布局,并且提到的图标位于文本前面。 这意味着没有一种很好的方法可以将它放在右侧。
基本上还有3个选项,或者至少我想到的选项。
使用自定义布局与drawable和edittext,我认为可以使用CollapsibleActionView或/和自定义动画完成一些效果(实际上取决于你需要它)
使用搜索视图,没有文字图标的样式:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:searchViewStyle">@style/appTheme.SearchView</item> </style> <style name="AppTheme.SearchView" parent="Widget.AppCompat.SearchView"> <item name="android:searchIcon" tools:targetApi="lollipop">@null</item> </style>
然后基本上将图标添加到正常的drawable。
我希望这项工作。 这个对我有用。
android:layoutDirection="rtl"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.