我使用的是的ImageButton
。但我不点击时获得的亮点。我GOOGLE了很多建议用其中显示另一个图像选择。有没有解决这个办法。通过仅使用一个图像,并强调它或给它一个发光效果。从而使用户知道按钮被点击
I am using an ImageButton
. But I don get the highlight when clicked. I googled and many suggested to use selector where another image is displayed. Is there any way around this. by using only one image and highlighting it or giving it a glow effect. so that the user knows that button has been clicked.
推荐答案
这其实并不是很困难的事情。你甚至都不需要创建2个独立的.png文件之类的东西。举例来说,如果你想有一个按钮,有一个梯度,然后更改它,当按钮被pssed $ P $:
This is actually not very difficult to do. You don't even need to create 2 seperate .png files or anything like that. For instance, if you want to have a button which has a gradient, and then change it when the button is pressed:
步骤1: 创建默认按钮梯度(绘制/ default_button.xml):
Step 1: Create default button gradient (drawable/default_button.xml):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="3dp" />
<gradient android:endColor="#8ba0bb" android:startColor="#43708f" android:angle="90" />
<stroke android:width="1dp" android:color="#33364252" />
</shape>
第2步:创建默认按钮pressed梯度(绘制/ default_button_ pressed.xml):
Step 2: Create default button pressed gradient (drawable/default_button_pressed.xml):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="3dp" />
<gradient android:endColor="#43708f" android:startColor="#8ba0bb" android:angle="90" />
<stroke android:width="1dp" android:color="#33364252" />
</shape>
第三步:创建选择(绘制/ default_button_selector.xml):
Step 3: Create selector (drawable/default_button_selector.xml):
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:state_pressed="true" android:drawable="@drawable/default_button_pressed" />
<item android:drawable="@drawable/default_button" />
</selector>
步骤4的(可选)的:为按钮创建的风格(价值/ style.xml):
Step 4 (optional): Create style for the button (values/style.xml):
<resources>
<style name="DefaultButton">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:background">@drawable/default_button_selector</item>
</style>
</resources>
第五步:使用按钮(布局/ main.xml中):
Step 5: use the button (layout/main.xml):
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<button style="@style/DefaultButton" />
</RelativeLayout>
正如你所看到的,它不是特别困难的事。
As you can see, it's not particularly difficult to do.
相关推荐
最新文章