XML中定义的形状半径未应用于按钮的聚焦和按下状态。
我有以下instagram_button_style.xml:
我有以下instagram_button_style.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/instagram_button_shape" android:state_focused="true" android:textColor="@color/colorAccent" />
<item android:drawable="@drawable/instagram_button_shape" android:state_pressed="true" android:textColor="@color/colorAccent" />
<item android:drawable="@color/colorButton" />
</selector>
我的 instagram_button_shape.xml 文件如下:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="30dp" />
<solid android:color="@color/colorButton" />
</shape>
</item>
<item android:drawable="@drawable/instagram_gradient" >
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="30dp" />
</shape>
</item>
</layer-list>
其中instagram_gradient是一张jpg图片
我将其用于按钮中,如下所示:
android:background="@drawable/instagram_button_style"
我的初始按钮状态:
我的按下按钮状态
期望:我希望按下状态有椭圆形按钮,但是半径并没有被应用。
最终更新:
最后,在进行了大量的调研之后,我改变了我的.jpg渐变文件为android_gradient形状文件。
@drawable/instagram_gradient
图层在实色图层之上,实色图层具有圆角,但自身没有设置圆角。 - Cruceo