How to set translucent background for layout programmatically?

There is a class in my application that extends the relative layout. I would like to know if there is any way that I could make the background of this class translucent programmatically. Since this is not an action, I cannot set the style attribute in the manifest file to Transparent, and I cannot use the setAlpha () method, since the setAlpha () method is applicable from API level 11 onwards, and my application has API level 11 and due to certain restrictions, I canโ€™t change it to API level 11. Could you direct me in this release?

Thanks.

+6
source share
1 answer

use setBackgroundResource or setBackgroundColor . I think at first itโ€™s pretty simple.

The second takes int as an argument. So, just convert your hexagonal color (e.g. #55000000 ) to decimal, and it will work as well.

However, it is better to use setBackgroundResource , because in this case you save your colors in a separate file:

 setBackgroundResource(R.color.mycolor); setBackgroundResource(android.R.color.transparent); //etc 
+8
source

Source: https://habr.com/ru/post/923345/


All Articles