Implemented clear button for EditText according to this. The button is really small and it is very hard to get touched. How to make button's touchable area bigger?

- 1
- 1

- 4,713
- 9
- 51
- 109
3 Answers
1) You can use a touch delegate
Android developer documentation
2) or put the button in a separate LinearLayout which wraps the content with the appropriate padding according to the size of the clickable area you want and set it clickable with the button inside as parameter.

- 1,390
- 2
- 13
- 21
-
1I found tutorial about touch delegate:http://www.daggie.be/?p=1006 It has line of code:bounds.right += 100; I understood this make touch area to the right. But I don't understant what is 100? Is it dp, sp, px? Do you reccomend doing it in this way – Joe Rakhimov Aug 13 '13 at 07:27
A possible way is to use an ImageButton where You set the image that You want to show as a button to "centerInside" and then use padding. For example:
<ImageButton
android:id="@+id/your_image_button"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@android:color/transparent"
android:scaleType="centerInside"
android:src="@drawable/your_selector"
android:padding="30dp"/>
if You set the background to transparent and us padding values, the picture will be smaller, but the buttons size will stay. This is just an example to show You what I mean, think about to set the right width/height values. Play with padding values until You reach what You want. The Image is a part of Your selector, that You have to set as src.

- 9,800
- 2
- 36
- 49
using padding attribute. "wrap_content" will be as big as its content plus padding.
<Button
android:id="@+id/calc_clear_txt_Prise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:padding="5dp"
android:layout_gravity="right|center_vertical"
android:background="@drawable/delete" />
The button will expand until it wraps both content and the padding.
Also, show us your code and we could help more accurately.

- 584
- 1
- 4
- 15
-
error: No resource identifier found for attribute 'layout_padding' in package 'android' – Joe Rakhimov Aug 12 '13 at 19:25