我正在尝试像这样在SearchView的末尾添加一个图标
这是我的实际代码:
<RelativeLayout
android:id="@+id/home_relativelayout_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_primary">
<android.support.v7.widget.SearchView
android:id="@+id/search_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColorHint="@color/grey_medium"
android:layout_margin="@dimen/mpoint_divider_padding"
android:gravity="center"
android:layout_centerVertical="true"
android:inputType="textNoSuggestions"
android:background="@drawable/wo_search_background" />
</RelativeLayout>
似乎没有android:drawableRight之类的属性,我什至尝试添加一个像ImageView的孩子,但屏幕上什么都没出现
是否可以通过SearchView实现我想要的功能,还是应该切换到EditText + ImageView?
感谢您的帮助
答案 0 :(得分:0)
您可以执行以下操作:
将类似ShapeDrawable
的内容添加到您的可绘制文件夹中:
Border.xml
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid android:color="@android:color/white" /> //Background color here
<stroke android:width="3dip" android:color="*Border color*"/>
</shape>
然后按如下所示添加SearchView:
<LinearLayout
android:layout_width="match_parent"
android:background="@drawable/Border"
android:layout_height="wrap_content"
android:Orientation="horizontal">
<android.support.v7.widget.SearchView
android:id="@+id/search_view"
android:layout_width="0dp"
android:layout_weight="4"
android:layout_height="wrap_content"
android:textColorHint="@color/grey_medium"
android:layout_margin="@dimen/mpoint_divider_padding"
android:gravity="center"
android:layout_centerVertical="true"
android:inputType="textNoSuggestions"
android:background="@drawable/wo_search_background" />
<ImageView android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
.../>
</LinearLayout>
使用此方法,您可以通过将点击事件添加到图片中来对其进行处理。
在查询和不起作用的情况下返回。