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

后端 未结 7 886
悲哀的现实
悲哀的现实 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:48

    First Method

     View someView = findViewById(R.id.randomViewInMainLayout);// get Any child View
    
      // Find the root view
      View root = someView.getRootView()
    
      // Set the color
      root.setBackgroundColor(getResources().getColor(android.R.color.red));
    

    Second Method

    Add this single line after setContentView(...);

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

    Third Method

    set background color to the rootView

    
    
    

    Important Thing

    rootView.setBackgroundColor(0xFF00FF00); //after 0x the other four pairs are alpha,red,green,blue color. 
    

提交回复
热议问题