Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.eurynomus.kontrolnosvetofar;
- import android.graphics.Color;
- import android.os.CountDownTimer;
- import android.support.constraint.ConstraintLayout;
- import android.support.v4.content.ContextCompat;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- public class MainActivity extends AppCompatActivity {
- ConstraintLayout mConstraintLayout;
- TextView red, yellow, green, txtGreen;
- Button button;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- mConstraintLayout = (ConstraintLayout) findViewById(R.id.constraintLayout);
- button = (Button) findViewById(R.id.button);
- red = findViewById(R.id.R);
- yellow = findViewById(R.id.Y);
- green = findViewById(R.id.G);
- txtGreen = findViewById(R.id.textViewGreen);
- button.setOnClickListener(new View.OnClickListener() {
- private int colorIndex = 1;
- @Override
- public void onClick(View view) {
- if(colorIndex==1){
- red.setBackgroundResource(R.color.Red);
- colorIndex = 0;
- }else if(colorIndex==0) {
- yellow.setBackgroundResource(R.color.Yellow);
- colorIndex = 2;
- }else if (colorIndex == 2){
- green.setBackgroundResource(R.color.Green);
- colorIndex = 3;
- txtGreen.setBackgroundResource(R.color.Green);
- } else if (colorIndex ==3){
- red.setBackgroundColor(0);
- yellow.setBackgroundColor(0);
- green.setBackgroundColor(0);
- txtGreen.setBackgroundColor(0);
- colorIndex = 1;
- }
- }
- });
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:id="@+id/constraintLayout"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- tools:context=".MainActivity"
- >
- <Button
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="8dp"
- android:layout_marginTop="8dp"
- android:layout_marginEnd="8dp"
- android:layout_marginBottom="8dp"
- android:text="Button"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.902"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent"
- app:layout_constraintVertical_bias="0.049" />
- <TextView
- android:id="@+id/R"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="151dp"
- android:layout_marginTop="88dp"
- android:layout_marginEnd="201dp"
- android:text="R"
- android:textSize="30sp"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.55"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toTopOf="parent" />
- <TextView
- android:id="@+id/Y"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="151dp"
- android:layout_marginTop="92dp"
- android:layout_marginEnd="201dp"
- android:text="Y"
- android:textSize="30sp"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.529"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/R" />
- <TextView
- android:id="@+id/G"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginStart="151dp"
- android:layout_marginTop="88dp"
- android:layout_marginEnd="201dp"
- android:text="G"
- android:textSize="30sp"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintHorizontal_bias="0.52"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/Y" />
- <TextView
- android:id="@+id/textViewGreen"
- android:layout_width="392dp"
- android:layout_height="151dp"
- android:layout_marginStart="3dp"
- android:layout_marginTop="183dp"
- android:layout_marginEnd="16dp"
- android:layout_marginBottom="6dp"
- app:layout_constraintBottom_toBottomOf="parent"
- app:layout_constraintEnd_toEndOf="parent"
- app:layout_constraintStart_toStartOf="parent"
- app:layout_constraintTop_toBottomOf="@+id/G" />
- </android.support.constraint.ConstraintLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement