Advertisement
mraps98

Change Color Activity Android Java

Feb 18th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.83 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement