setting transparency to buttons in android

前端 未结 12 1090
悲&欢浪女
悲&欢浪女 2021-02-03 23:28

I want to make Buttons with different transparency levels in android.I have used \"@android:color/transparent\". But it makes the button 100% transparent. I need a

相关标签:
12条回答
  • 2021-02-04 00:12

    Using XML

    If you want to set color and along with that if you want to set transparent then you have to use that color code .

    android:color="#66FF0000"    // Partially transparent red
    android:alpha="0.25"         // 25% transparent 
    

    Using java

    And if you want to set dynamically (java code)then try this,

    myButton.getBackground().setAlpha(64);  // 25% transparent
    

    - i.e .INT ranges from 0 (fully transparent) to 255 (fully opaque)

    0 讨论(0)
  • 2021-02-04 00:12

    To set the background of button as transparent do:

        android:background="@android:color/transparent"
    
    0 讨论(0)
  • 2021-02-04 00:13

    You can set a background for the button,then achieve the transparency by adjusting the alpha attribute of the button,

    android:alpha="0.7"
    

    Makes the opacity 70 percent.

    0 讨论(0)
  • 2021-02-04 00:13

    You can set transparency with color. In Android color is broken into 4 8-bit (0-255) segments, with the first 8-bit (0-255) controlling the alpha. For example with the basic color code for Light Gray: D3D3D3. If I want light grey transparent, add 0 and to light grey and get 0D3d3d3 for 100% transparent, or 227(E3 in hex) and get E3D3D3D3 for 50% or 255(FF in Hex) and get FFD3D3D3 for 0%

    0 讨论(0)
  • 2021-02-04 00:14

    Use this code in your background color

    android:background="?android:attr/selectableItemBackground"
    
    0 讨论(0)
  • 2021-02-04 00:14

    Just Use '@null' to background of button makes transparency in button

    android:background="@null"
    
    0 讨论(0)
提交回复
热议问题