This is my shape
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#80000000"
android:endColor="#80FFFFFF"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
android:right="7dp"
android:bottom="7dp" />
<corners android:radius="10dp" />
</shape>
This is what I want for button pressed
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
android:startColor="#80FFFFFF"
android:endColor="#80000000"
android:angle="45"/>
<padding android:left="7dp"
android:top="7dp"
andro开发者_运维百科id:right="7dp"
android:bottom="7dp" />
<corners android:radius="10dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/button_pressed" /> <!-- pressed -->
<item android:state_focused="true"
android:drawable="@drawable/button_focused" /> <!-- focused -->
<item android:drawable="@drawable/button_normal" /> <!-- default -->
</selector>
I tried this code to link to the two shapes but when I set it as background it just made my button default gray.
and I added the selector to the background of my button, it has the right opacity as is but I need it to show a different colour (like white or something) when it is clicked.
anyone any idea?
I do it in this way:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/btn_bg_pressed"/>
<item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/btn_bg_pressed"/>
<item android:state_focused="true" android:drawable="@drawable/btn_bg_selected"/>
<item android:state_focused="false" android:state_pressed="false" android:drawable="@android:color/transparent"/>
</selector>
This is what i usually use for my theme
精彩评论