SHARE
TWEET

Change Color Activity Android Java

mraps98 Feb 18th, 2020 70 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.example.helloworld;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4. import androidx.constraintlayout.widget.ConstraintLayout;
  5.  
  6. import android.graphics.Color;
  7. import android.os.Bundle;
  8. import android.view.View;
  9.  
  10. public class MainActivity extends AppCompatActivity {
  11.  
  12.     @Override
  13.     protected void onCreate(Bundle savedInstanceState) {
  14.         super.onCreate(savedInstanceState);
  15.         setContentView(R.layout.activity_main);
  16.     }
  17.  
  18.     public void changeColor(View view){
  19.         ConstraintLayout cl = findViewById(R.id.constraintLayout);
  20.  
  21.         switch(view.getId()){
  22.             case R.id.button1:
  23.                 cl.setBackgroundColor(Color.parseColor("#000000"));break;
  24.             case R.id.button2:
  25.                 cl.setBackgroundColor(Color.parseColor("#ffffff")); break;
  26.         }
  27.     }
  28.  
  29. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top