Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.home1
- import android.graphics.Color
- import android.os.Bundle
- import android.view.View
- import android.widget.Button
- import android.widget.EditText
- import android.widget.TextView
- import android.widget.Toast
- import androidx.activity.enableEdgeToEdge
- import androidx.appcompat.app.AppCompatActivity
- import androidx.core.view.ViewCompat
- import androidx.core.view.WindowInsetsCompat
- import org.w3c.dom.Text
- class MainActivity : AppCompatActivity() {
- override fun onCreate(savedInstanceState: Bundle?) {
- super.onCreate(savedInstanceState)
- enableEdgeToEdge()
- setContentView(R.layout.activity_main)
- ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
- val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
- v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
- insets
- }
- val mybtn = findViewById<Button>(R.id.button)
- mybtn.setOnClickListener {
- val year = findViewById<EditText>(R.id.editTextNumber)
- val tv = findViewById<TextView>(R.id.textView)
- val st = year.text.toString().toInt()
- if (st < 1950 || st > 2020) {
- Toast.makeText(this, "Грешна година", Toast.LENGTH_SHORT).show()
- } else {
- val age = 2025-st
- tv.text = "Ти си на $age години"
- val tv = findViewById<TextView>(R.id.textView2)
- if (age < 13) {
- tv.text = "Дете"
- tv.setBackgroundColor(Color.GREEN)
- } else if (age < 20) {
- tv.text = "Тинейджър"
- tv.setBackgroundColor(Color.RED)
- } else if (age < 68) {
- tv.text = "Възрастен"
- tv.setBackgroundColor(Color.BLUE)
- } else {
- tv.text = "Пенсионер"
- tv.setBackgroundColor(Color.GRAY)
- }
- }
- }
- }
- fun btn_exit(view: View) {
- finish()
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement