Created
April 4, 2022 12:13
-
-
Save evik246/e3a78fb43fbc085323a0cf673b637b6e to your computer and use it in GitHub Desktop.
Меняет цвет кнопки при нажатии
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.colorbutton; | |
import androidx.appcompat.app.AppCompatActivity; | |
import android.graphics.Color; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import java.util.Random; | |
public class MainActivity extends AppCompatActivity { | |
static Random random; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
random = new Random(); | |
} | |
public void RandomColor(View view) { | |
Button button = (Button) view; | |
button.setBackgroundColor(Color.rgb(random.nextInt(255), random.nextInt(255), random.nextInt(255))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment