简体   繁体   中英

Create Custom Search Bar

I would like to add a search bar to my activity that should look like this:

在此处输入图片说明

My Layout.xml looks like this:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout android:orientation="horizontal"
style="@android:style/ButtonBar" android:id="@+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true">
<EditText android:id="@+id/ean" android:layout_width="100dp"
android:layout_height="fill_parent" android:layout_weight="1.5"/>
<Button android:id="@+id/search" android:layout_width="0.0dip"
android:layout_height="fill_parent" android:text="@string/Search"
android:layout_weight="1.0" />
</LinearLayout>

<LinearLayout android:orientation="horizontal"
style="@android:style/ButtonBar" android:id="@+id/footer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button android:id="@+id/cancel" android:layout_width="0.0dip"
android:layout_height="fill_parent" android:text="@string/cancel"
android:layout_weight="1.0" />
<Button android:id="@+id/light" android:layout_width="0.0dip"
android:layout_height="fill_parent" android:text="@string/light"
android:layout_weight="1.0" />
</LinearLayout>

The Graphical Layout looks like this: 在此处输入图片说明

How can i style my layout that it looks like in the image above?

I'd try and replace the Button by an ImageButton . Then I'd create 9patch images for both the button and the text box and assign them using a style.

is just nothing. just design your theme in xml layout file with that particulate background and add one editText and button as per your design and access that by activity.

comment me if need further help.

thanks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM