How to set transparency of a background image Android xml file

后端 未结 9 665
南笙
南笙 2020-12-08 02:24

I have put an image in as the background of my android application with the following line of code:

 android:background=\"@drawable/background\"
相关标签:
9条回答
  • 2020-12-08 03:03

    You can set the alpha property:

    android:alpha="0.4"
    

    via code :

    yourView.setAlpha(0.5f);
    

    only the background :

    yourView.getBackground().setAlpha(120);  // here the value is an integer not float
    
    0 讨论(0)
  • 2020-12-08 03:04

    just use this line in your .xml file android:background="#ddxxxxxx" replace the xxxxxx with any color you want. refer https://alvinalexander.com/android/how-background-image-behind-translucent-opaque-textview for more details.

    0 讨论(0)
  • 2020-12-08 03:07

    you can create a layer-list resource and set it to background property of your view (layout)

    background_image_with_alpha.xml

    <?xml version="1.0" encoding="utf-8"?>
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    
        <item>
            <bitmap
                android:alpha="0.2"
                android:src="@drawable/xxxxxx"
                android:gravity="fill">
    
            </bitmap>
        </item>
    
    </layer-list >
    
    0 讨论(0)
提交回复
热议问题