嗨 在我的应用程序中包含一个按钮,目前我使用 xml 自定义更改背景并且它在 2.1 中工作正常但是当我达到 2.2 时,按钮很难点击,我该如何解决这个问题?
下面给出了我的按钮 xml 代码
<Button
android:id ="@+id/Button_Continue1"
android:background="@drawable/continue_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
/>
最佳答案
如果您的按钮很小且难以点击,请使用 Inset Drawable .您设置要显示的可绘制对象以及左侧、顶部、右侧和底部的插图。插图就像某种边距但可点击。
这是一个例子。
<?xml version="1.0" encoding="UTF-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/your_drawable"
android:insetTop="10dp"
android:insetRight="10dp"
android:insetBottom="10dp"
android:insetLeft="10dp"/>
这将使您的按钮在触摸事件的每一侧都高 10dp
。按钮的外观不会改变。
现在在您的布局中,您不再将原始可绘制对象设置为 Button
的背景,而是将新的 Inset Drawable
设置为背景。
关于Android 按钮在 2.2 中很难被击中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4408346/