Android: Changing Background-Color of the Activity (Main View)

后端 未结 7 888
悲哀的现实
悲哀的现实 2020-11-30 04:24

I want to change the background color of my Main-View (not a Button or a Text-View) just the real background which is usually black... I got this code:

view.         


        
7条回答
  •  忘掉有多难
    2020-11-30 04:49

    I just want to add my 2 cents. I had the same goal (to change the background color from the .java class). But none of the above methods worked for me.

    Issue was, that I set the background color inside the layout .xml file with android:background="@color/colorGray":

    
    
    

    So I just deleted particular line:

    
    
    

    Now I (you) can set the color from the code with:

    getWindow().getDecorView().setBackgroundColor(Color.GRAY);
    

提交回复
热议问题