开发者

Making a button semi-transparent in android [duplicate]

This question already has answers here: 开发者_运维百科 Closed 11 years ago.

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.


  1. Use the alpha property for the transparency of the color. Also see this thread.
  2. 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>
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜