应用Edittext实现搜索框的功能

因为产品部的要求,希望将搜索框改版一下,具体要求是提示图标和提示文字都要居于Edittext下方。关键是设置了gravity属性之后,文本可以居于图标下方。但是运用android:drawableLeft属性设置图标时图标仍然继续居中,各种捣鼓无果。

    于是转换思路,不应用drawableLeft属性,而是想文本框左边添加ImageButton,设置layout_gravity属性,一击即中.

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
     < LinearLayout
         android:id = "@+id/search"
         android:layout_width = "match_parent"
         android:layout_below = "@id/title"
         android:focusable = "true"
         android:focusableInTouchMode = "true"
         android:orientation = "horizontal"  >
         < ImageButton
             android:layout_width = "wrap_content"
             android:layout_height = "wrap_content"
             android:background = "@null"
             android:src = "@drawable/search"
             android:layout_gravity = "bottom"
/>
         < EditText
             android:id = "@+id/edit_text"
             android:layout_width = "0dp"
             android:layout_height = "match_parent"
             android:layout_weight = "1.0"
             android:background = "@null"
             android:gravity = "bottom"
             android:hint = "提示框"
             android:singleLine = "true"
             android:textColor = "@android:color/black"
             android:textColorHint = "#CCCCCE"
             android:textCursorDrawable = "@null"
             android:textSize = "@dimen/H3"  />
         < ImageButton
             android:id = "@+id/btn_clear"
             android:layout_width = "wrap_content"
             android:layout_height = "wrap_content"
             android:background = "@null"
             android:src = "@drawable/comm_ad_close"
             android:layout_gravity = "bottom"
             android:visibility = "gone"  />
     </ LinearLayout >

    效果图如下:

    如果有其他方法实现这种效果,欢迎赐教.......

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值