Possible Duplicate:
How to Set Opacity (Alpha) for View in Android
i want to ask two questions:
1) i want to make the buttons in my main.xml
i.e simply the first screen look semi-transparent.
It should be such that the background image can be partly-seen through it. But the button should maintain its normal size and looks.
2)(This is regarding another button in another view) i changed the background of buttons using
android:background="#2563EA"
but now when it is clicked it does not change its color. how can i reset it. also can anyone tell me how to give it a new onClick
color.
To change the appearance of a button depending on state, use a StateList.
- Use the alpha property for the transparency of the color. Also see this thread.
You can dynamically change the color by using the
OnTouch
event. Or better, you can assign the background in the XML to be a selector.<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>
精彩评论