使EditText成为可点击的一部分?
如果您覆盖boolean onTouch(View v, MotionEvent event)
,我相信这是可能的。不过,实际上,如果您将ImageView
的搜索图标放在EditText
的右侧,并且只需点击ImageView
即可实现。
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<EditText
android:layout_toLeftOf="@id/search"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/search"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:src="@android:drawable/ic_search_category_default"
android:layout_height="wrap_content" />
</RelativeLayout>
onTouch的问题是要知道要计数的区域,而不是将其与文本重叠。这正确的答案是这样的。 –
你总是可以添加正确的填充以确保文本不会覆盖图像...但它仍然不是我推荐的模式:) – Jon
谢谢@GabeSechan是不是只能使图标的可点击部分成为可能(这是9个补丁映像的非可缩放部分)? – hereForLearing
不,不是那样。编辑文本如何知道9补丁背景的哪一部分是搜索图标? –