• Предмет: Информатика
  • Автор: parsinaanaa120
  • Вопрос задан 4 месяца назад

Создайте светофор по следующему примеру, добавьте ему возможность переключать цвета по нажатию на любые кнопки(помогите пожалуйста срочно)

Ответы

Ответ дал: daniilakovlev853
0

Ответ:

бирёж цвет и рисуеш сфитовор а пото разукрашваеш

Ответ дал: AllexeyDo122
0

Kotlin приложение

package ru.alexanderklimov.trafficlight

import android.graphics.Color

import android.os.Bundle

import android.widget.Button

import android.widget.TextView

import androidx.appcompat.app.AppCompatActivity

import androidx.constraintlayout.widget.ConstraintLayout

class MainActivity : AppCompatActivity() {

   override fun onCreate(savedInstanceState: Bundle?) {

       super.onCreate(savedInstanceState)

       setContentView(R.layout.activity_main)

 

       val rootLayout: ConstraintLayout = findViewById(R.id.layout_root)

       val textView: TextView = findViewById(R.id.textView)

       val redButton: Button = findViewById(R.id.button_red)

       val yellowButton: Button = findViewById(R.id.button_yellow)

       val greenButton: Button = findViewById(R.id.button_green)

       redButton.setOnClickListener {

           textView.text = "Красный"

           root_layout.setBackgroundColor(resources.getColor(R.color.redColor, null))

       }

       yellowButton.setOnClickListener {

           textView.setText(R.string.yellow)

           root_layout.setBackgroundColor(ContextCompat.getColor(this, R.color.yellowColor))

       }

       greenButton.setOnClickListener {

           textView.text = resources.getText(R.string.green)

           root_layout.setBackgroundColor(Color.GREEN)

       }

   }

}

Вас заинтересует