Advertisement
praymes

SvetofarPurvoKontrolno

May 15th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.28 KB | None | 0 0
  1. package com.example.eurynomus.kontrolnosvetofar;
  2.  
  3. import android.graphics.Color;
  4. import android.os.CountDownTimer;
  5. import android.support.constraint.ConstraintLayout;
  6. import android.support.v4.content.ContextCompat;
  7. import android.support.v7.app.AppCompatActivity;
  8. import android.os.Bundle;
  9. import android.util.Log;
  10. import android.view.View;
  11. import android.widget.Button;
  12. import android.widget.TextView;
  13.  
  14. public class MainActivity extends AppCompatActivity {
  15.  
  16. ConstraintLayout mConstraintLayout;
  17. TextView red, yellow, green, txtGreen;
  18. Button button;
  19.  
  20. @Override
  21. protected void onCreate(Bundle savedInstanceState) {
  22. super.onCreate(savedInstanceState);
  23. setContentView(R.layout.activity_main);
  24.  
  25. mConstraintLayout = (ConstraintLayout) findViewById(R.id.constraintLayout);
  26. button = (Button) findViewById(R.id.button);
  27. red = findViewById(R.id.R);
  28. yellow = findViewById(R.id.Y);
  29. green = findViewById(R.id.G);
  30. txtGreen = findViewById(R.id.textViewGreen);
  31.  
  32.  
  33.  
  34.  
  35. button.setOnClickListener(new View.OnClickListener() {
  36. private int colorIndex = 1;
  37. @Override
  38. public void onClick(View view) {
  39. if(colorIndex==1){
  40. red.setBackgroundResource(R.color.Red);
  41. colorIndex = 0;
  42. }else if(colorIndex==0) {
  43. yellow.setBackgroundResource(R.color.Yellow);
  44. colorIndex = 2;
  45. }else if (colorIndex == 2){
  46. green.setBackgroundResource(R.color.Green);
  47. colorIndex = 3;
  48. txtGreen.setBackgroundResource(R.color.Green);
  49.  
  50. } else if (colorIndex ==3){
  51.  
  52. red.setBackgroundColor(0);
  53. yellow.setBackgroundColor(0);
  54. green.setBackgroundColor(0);
  55. txtGreen.setBackgroundColor(0);
  56. colorIndex = 1;
  57. }
  58.  
  59.  
  60.  
  61.  
  62. }
  63.  
  64. });
  65.  
  66. }
  67.  
  68. }
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78. <?xml version="1.0" encoding="utf-8"?>
  79. <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
  80. xmlns:app="http://schemas.android.com/apk/res-auto"
  81. xmlns:tools="http://schemas.android.com/tools"
  82. android:id="@+id/constraintLayout"
  83. android:layout_width="match_parent"
  84. android:layout_height="match_parent"
  85. tools:context=".MainActivity"
  86. >
  87.  
  88. <Button
  89. android:id="@+id/button"
  90. android:layout_width="wrap_content"
  91. android:layout_height="wrap_content"
  92. android:layout_marginStart="8dp"
  93. android:layout_marginTop="8dp"
  94. android:layout_marginEnd="8dp"
  95. android:layout_marginBottom="8dp"
  96. android:text="Button"
  97. app:layout_constraintBottom_toBottomOf="parent"
  98. app:layout_constraintEnd_toEndOf="parent"
  99. app:layout_constraintHorizontal_bias="0.902"
  100. app:layout_constraintStart_toStartOf="parent"
  101. app:layout_constraintTop_toTopOf="parent"
  102. app:layout_constraintVertical_bias="0.049" />
  103.  
  104. <TextView
  105. android:id="@+id/R"
  106. android:layout_width="wrap_content"
  107. android:layout_height="wrap_content"
  108. android:layout_marginStart="151dp"
  109. android:layout_marginTop="88dp"
  110. android:layout_marginEnd="201dp"
  111. android:text="R"
  112. android:textSize="30sp"
  113. app:layout_constraintEnd_toEndOf="parent"
  114. app:layout_constraintHorizontal_bias="0.55"
  115. app:layout_constraintStart_toStartOf="parent"
  116. app:layout_constraintTop_toTopOf="parent" />
  117.  
  118. <TextView
  119. android:id="@+id/Y"
  120. android:layout_width="wrap_content"
  121. android:layout_height="wrap_content"
  122. android:layout_marginStart="151dp"
  123. android:layout_marginTop="92dp"
  124. android:layout_marginEnd="201dp"
  125. android:text="Y"
  126. android:textSize="30sp"
  127. app:layout_constraintEnd_toEndOf="parent"
  128. app:layout_constraintHorizontal_bias="0.529"
  129. app:layout_constraintStart_toStartOf="parent"
  130. app:layout_constraintTop_toBottomOf="@+id/R" />
  131.  
  132. <TextView
  133. android:id="@+id/G"
  134. android:layout_width="wrap_content"
  135. android:layout_height="wrap_content"
  136. android:layout_marginStart="151dp"
  137. android:layout_marginTop="88dp"
  138. android:layout_marginEnd="201dp"
  139. android:text="G"
  140. android:textSize="30sp"
  141. app:layout_constraintEnd_toEndOf="parent"
  142. app:layout_constraintHorizontal_bias="0.52"
  143. app:layout_constraintStart_toStartOf="parent"
  144. app:layout_constraintTop_toBottomOf="@+id/Y" />
  145.  
  146. <TextView
  147. android:id="@+id/textViewGreen"
  148. android:layout_width="392dp"
  149. android:layout_height="151dp"
  150. android:layout_marginStart="3dp"
  151. android:layout_marginTop="183dp"
  152. android:layout_marginEnd="16dp"
  153. android:layout_marginBottom="6dp"
  154. app:layout_constraintBottom_toBottomOf="parent"
  155. app:layout_constraintEnd_toEndOf="parent"
  156. app:layout_constraintStart_toStartOf="parent"
  157. app:layout_constraintTop_toBottomOf="@+id/G" />
  158.  
  159.  
  160. </android.support.constraint.ConstraintLayout>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement