开发者

Handling click on EditText's rightDrawable image

开发者 https://www.devze.com 2023-02-11 02:22 出处:网络
I\'m implementing a custom search bar in my Android application. This s开发者_StackOverflowearch bar is just an EditText with a magnifier set to leftDrawable property. My problem is that I don\'t know

I'm implementing a custom search bar in my Android application. This s开发者_StackOverflowearch bar is just an EditText with a magnifier set to leftDrawable property. My problem is that I don't know how to get noticed when the user clicks the magnifier. Is there any listener for doing this? Am I using the recommended approach to implement this search bar? I know I could use an EditText and an ImageButton on its right side, but I want the magnifier to be inside the EditText.


Is there any listener for doing this?

Not specifically for that image.

Am I using the recommended approach to implement this search bar?

I am not aware that there are recommendations for implementing a search bar. It is not the way Google elected to implement a clickable button for their search bar, which has the button to the right of the field.

You may be able to have the desired effect by:

  1. Putting the EditText in a RelativeLayout
  2. Adding a transparent View as a later child of the EditText, sized to match the size of your image
  3. Using margins to have the transparent View be over top of your image
  4. Setting an OnClickListener on the transparent View
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号