MainActivity.kt
package com.example.jetpack
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val context = this
// set image view image from drawable
imageView.setImageDrawable(ContextCompat.getDrawable(
context,R.drawable.flower
))
}
}
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"
android:background="#636C5A"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:srcCompat="@tools:sample/avatars" />
</androidx.constraintlayout.widget.ConstraintLayout>

- android kotlin - Drawable tint programmatically
- android kotlin - Convert drawable to bitmap
- android kotlin - Create GradientDrawable Programmatically
- android kotlin - ActionBar background color programmatically
- android kotlin - Display logo on ActionBar
- android kotlin - ActionBar title style
- android kotlin - ActionBar title padding left
- android kotlin - Get ActionBar height
- android kotlin - Checkable menu item
- android kotlin - Popup menu with icons
- android kotlin - Menu add remove update item programmatically
- android kotlin - Menu icon color
- android kotlin - Menu overflow icon
- android kotlin - CalendarView set date
- android kotlin - CalendarView example