Skip to content

Instantly share code, notes, and snippets.

@evik246
Created April 4, 2022 12:13
Show Gist options
  • Save evik246/e3a78fb43fbc085323a0cf673b637b6e to your computer and use it in GitHub Desktop.
Save evik246/e3a78fb43fbc085323a0cf673b637b6e to your computer and use it in GitHub Desktop.
Меняет цвет кнопки при нажатии
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