MainActivity.kt
package com.example.jetpack
import android.graphics.Typeface
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// set checkbox checked change listener
checkBox.setOnCheckedChangeListener{ buttonView, isChecked ->
if (isChecked){
textView.text = "CheckBox is checked."
buttonView.setTypeface(null,Typeface.ITALIC)
}else{
textView.text = "CheckBox is unchecked."
buttonView.setTypeface(null,Typeface.NORMAL)
}
}
}
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.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"
android:background="#EDEAE0">
<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Check Me"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
tools:text="TextView"
android:textSize="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBox" />
</androidx.constraintlayout.widget.ConstraintLayout>


- android kotlin - Set CardView elevation
- android kotlin - Set CardView background color
- android kotlin - Set CardView corner radius
- android kotlin - RadioButton with image and text
- android kotlin - RadioButton circle color programmatically
- android kotlin - RadioButton onClick event
- android kotlin - TextView margin programmatically
- android kotlin - TextView html formatted text
- android kotlin - TextView add border programmatically
- android kotlin - Coroutines with timeout
- android kotlin - Coroutines JSON from URL
- android kotlin - Room with coroutines
- android kotlin - Coroutines async await all
- android kotlin - Coroutines async
- android kotlin - Canvas draw circle