我有这个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>
答案 0 :(得分:0)
如果我是正确的,这是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。
答案 1 :(得分:0)
我希望这项工作。它对我有用。
android:layoutDirection="rtl"