2011-09-29 175 views
0

我想添加一个搜索栏,以我的活动看起来应该像这样的:创建自定义搜索栏

enter image description here

我Layout.xml看起来是这样的:

<?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> 

图形布局看起来像这样: enter image description here

我如何设计我的布局,看起来像上面的图片?

回答

1

我想尝试用ImageButton代替Button。然后,我会为按钮和文本框创建9patch图像,并使用样式分配它们。

+0

你想介绍一些关于9patch图像的信息吗? –

+0

嗯当然我编辑我的答案。 – milind

+0

http://developer.android.com/guide/developing/tools/draw9patch.html –

0

就是没有。只需在具有微粒背景的xml布局文件中设计您的主题 并根据您的设计添加一个editText和按钮并按活动访问。

评论我,如果需要进一步帮助。

谢谢

+0

你介意以prive为例吗? –

+0

我添加代码在Thorsten Dittmar和misteck你可以在那里看到。 – milind