公司项目要做一个搜索框,像我这样的小白菜也不行,只能去百度+谷歌,据说有个什么什么搜索控件,看了一下觉得有些麻烦,我觉得一定还有更简单的办法,黄天不负有心,最后终于叫我找到了,整理了一下基本搞定。下面就是贴源码了哈。。。
1,第一要配置一个xml文件,这个文件主要是做框的(shape.xml)我把它放在了drawable目录下。
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000"/>
<stroke android:width="1dp" android:color="#EAEAEA"/>
<padding android:left="1dp" android:top="1dp" android:right="1dp" android:bottom="1dp" />
</shape>
2,第二就是创建一个显示布局的xml文件了(search.xml)(注意红色的位置)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ll_status_selector"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/ll_status_selector"
android:orientation="horizontal"
>
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="210dip"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dip"
android:background="@drawable/shape"
>
<EditText
android:id="@+id/editTextsearch"
android:layout_width="40dip"
android:layout_height="35dip"
android:layout_weight="1"
android:textSize="15dip"
android:singleLine="true"
android:hint="点击这里输入..."
android:background="#FFFFFF" />
<Button
android:id="@+id/searchbutton"
android:layout_width="wrap_content"
android:layout_height="35dip"
android:background="@drawable/edit"
/>
</LinearLayout>
<Button
android:id="@+id/backhbutton"
android:layout_width="70dip"
android:layout_height="36dip"
android:layout_marginTop="10dip"
android:layout_marginLeft="25dip"
android:background="#CCCCCC"
android:textColor="#ffffff"
android:text="返回" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ll_status_selector" >
<Button
android:layout_width="1333dip"
android:layout_height="2dip"
android:layout_marginTop="5dip"
android:background="@drawable/abs__tab_selected_holo"
/>
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/ll_status_selector"
/>
</LinearLayout>
</LinearLayout>
哈哈大功告成了亲们,可以显示在Activity中了!!!