Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package hu.dani.teszt.examples.teszt;
- import android.graphics.Color;
- import android.os.Bundle;
- import android.support.v7.app.ActionBarActivity;
- import android.view.View;
- import android.widget.Button;
- import android.widget.LinearLayout;
- import android.widget.RelativeLayout;
- import java.util.Random;
- public class MainActivity extends ActionBarActivity {
- private String[] colorCodes={"#FFFFFF", "#000000", "#FFFF00", "#FF99FF", "#99FF00", "#FF3300", "#996600"};
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final Random rand= new Random();
- int number1;
- RelativeLayout rL1= (RelativeLayout) findViewById(R.id.rL);
- rL1.setBackgroundColor(Color.parseColor(colorCodes[0]));
- /*number1= rand.nextInt(6)+1;
- final LinearLayout lL1 = (LinearLayout) findViewById(R.id.lL1);
- lL1.setBackgroundColor(Color.parseColor(colorCodes[number1]));
- number1= rand.nextInt(6)+1;
- final LinearLayout lL2 = (LinearLayout) findViewById(R.id.lL2);
- lL2.setBackgroundColor(Color.parseColor(colorCodes[number1]));
- number1= rand.nextInt(6)+1;
- final LinearLayout lL3 = (LinearLayout) findViewById(R.id.lL3);
- lL3.setBackgroundColor(Color.parseColor(colorCodes[number1]));
- Button btnNewRandom= (Button) findViewById(R.id.btnNewRandom);
- btnNewRandom.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- int number2;
- number2= rand.nextInt(6)+1;
- lL1.setBackgroundColor(Color.parseColor(colorCodes[number2]));
- number2= rand.nextInt(6)+1;
- lL2.setBackgroundColor(Color.parseColor(colorCodes[number2]));
- number2= rand.nextInt(6)+1;
- lL3.setBackgroundColor(Color.parseColor(colorCodes[number2]));
- }
- });
- Button btnBlueee= (Button) findViewById(R.id.btnBlueee);
- btnBlueee.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- lL1.setBackgroundColor(getResources().getColor(R.color.blue));
- lL2.setBackgroundColor(getResources().getColor(R.color.blue));
- lL3.setBackgroundColor(getResources().getColor(R.color.blue));
- }
- });*/
- final int[] colorArray = getResources().getIntArray(R.array.color_names);
- int randomColorName = colorArray[rand.nextInt(colorArray.length)];
- /* String resName= getResources().getResourceEntryName(randomColorName);
- TextView tvResName= (TextView) findViewById(R.id.textView);
- tvResName.setText(resName);*/
- final LinearLayout lL4 = (LinearLayout) findViewById(R.id.lL4);
- lL4.setBackgroundColor(randomColorName);
- final LinearLayout lL5 = (LinearLayout) findViewById(R.id.lL5);
- lL5.setBackgroundColor(randomColorName);
- final LinearLayout lL6 = (LinearLayout) findViewById(R.id.lL6);
- lL6.setBackgroundColor(randomColorName);
- Button btnNewRandom2= (Button) findViewById(R.id.btnNewRandom2);
- btnNewRandom2.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- int randomColorName2;
- randomColorName2 = colorArray[rand.nextInt(colorArray.length)];
- lL4.setBackgroundColor(randomColorName2);
- randomColorName2 = colorArray[rand.nextInt(colorArray.length)];
- lL5.setBackgroundColor(randomColorName2);
- randomColorName2 = colorArray[rand.nextInt(colorArray.length)];
- lL6.setBackgroundColor(randomColorName2);
- }
- });
- lL4.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // Toast.makeText(MainActivity.this, lL4.getTag().toString(), Toast.LENGTH_SHORT).show();
- }
- });
- lL5.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // Toast.makeText(MainActivity.this, lL5.getTag().toString(), Toast.LENGTH_SHORT).show();
- }
- });
- lL6.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // Toast.makeText(MainActivity.this, lL6.getTag().toString(), Toast.LENGTH_SHORT).show();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement