Android:搜索框设计

时间:2012-12-17 08:47:12

标签: android android-layout android-edittext autocompletetextview

我想在我的应用中设计一个搜索框,如下所示:
search icon

当我点击它时,它应该扩展如下:

search box

但是,我没有得到如何实现这一目标。

4 个答案:

答案 0 :(得分:1)

你应该使用RelativeLayout&设置ImageView align_parent_top& align_parent_right 或者如果您使用LinearLayout,那么您可以尝试这种方式:---

<LinearLayout
    android:id="@+id/ll_my_profile"
    android:layout_width="fill_parent"
    android:layout_height="45dp"
    android:layout_marginLeft="10dp"
     android:clickable="true"
    android:layout_marginRight="10dp"
    android:background="@drawable/txt_box_bg"
    android:orientation="horizontal" >

    <TextView
        android:id="@+id/my_profile"
        android:layout_width="0dip"
        android:layout_height="45dp"
        android:layout_weight="1"
        android:gravity="left"
        android:hint="My Profile"
        android:padding="10dp"
        android:textColor="#000000"
        android:textSize="18dp" />

    <ImageView
        android:id="@+id/img_for_setting"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="right|center_vertical"
        android:background="@drawable/arrow" />
</LinearLayout>

答案 1 :(得分:0)

您是否尝试过移动Jquery实用程序?实现这一点应该不难。

答案 2 :(得分:0)

根据应用中搜索框的使用方式,最适合使用Action Views in the ActionBar。这是Google建议的在Activity中包含可扩展的响应式搜索框的方法。

对于SDK 11之前的Android版本,您可以使用兼容性库ActionBarSherlock实现所有相同的功能。虽然我自己没有在ActionBarSherlock中使用可扩展搜索栏,但看起来这里可以使用SearchView。

希望有所帮助!

答案 3 :(得分:0)

创建线性布局。将其背景设置为完整的编辑框图像。在线性布局内添加一个编辑框和按钮。将按钮的背景设置为android:background =“@ drawable / searchbtn”。 将编辑框的背景设置为无图像(透明图像)。完成。