简体   繁体   中英

Transparent bitmap as background

I am trying to make my background bitmap a little bit transparent so text could be a little bit more visible.

I am setting my background bitmap like this:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:dither="true"
    android:src="@drawable/bitmap"
    android:tileMode="repeat" />

This way text is not visible at all. How can I make my bitmap transparent? Thank you!

In the layout file add set an ID to the root layout:

<LinearLayout android:id="@+id/background" android:background="...

And you can change the opacity of its background in the code:

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout....);

    View backgroundView = findViewById(R.id.background);
    backgroundView.getBackground().setAlpha(50);
    ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM