Android Layout background alpha

前端 未结 4 1325
遥遥无期
遥遥无期 2021-01-31 18:26

Hi I have a layout which I\'m using to fill my page and I have to set a background image held in my drawable folder in that layout.

I want to then set the <

相关标签:
4条回答
  • 2021-01-31 19:06

    You Can Set Alpha for Drawables not Views ! You Can get background as a drawable and do like this :

    View backgroundimage = (View) findViewById(R.id.background);
    backgroundimage.getBackground().setAlpha(80);
    
    0 讨论(0)
  • 2021-01-31 19:08

    Try to use:

    Drawable.setAlpha();
    

    You should do something like this:

    View backgroundImage = findViewById(R.id.background);
    Drawable background = backgroundImage.getBackground();
    background.setAlpha(80);
    
    0 讨论(0)
  • 2021-01-31 19:15

    If you want to set alpha in xml then u can try this:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/background"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#CC000000" >
    

    first 2 digits are used to set alpha here alpha is 80% next 6 digits for color code

    Hence, alpha is set in hexadecimal coding. FF = 100% and 00 = 0%, thus 80% is not 80 in hexadecimal, for more standard values see this post.

    0 讨论(0)
  • 2021-01-31 19:22

    Use This on your LinearLayout

    android:background="#92000000"

    0 讨论(0)
提交回复
热议问题