MainActivity.kt
package com.cfsuman.kotlintutorials
import android.graphics.Color
import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.GradientDrawable
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
// If the support action bar is available
supportActionBar?.apply {
title = "ActionBar background color"
// Set action bar background color
setBackgroundDrawable(
ColorDrawable(
Color.parseColor("#8FBC8F")
)
)
// We can also show gradient background in action bar
// Uncomment below line to see gradient background
//setBackgroundDrawable(gradientDrawable())
}
}
}
// Method to generate gradient drawable
private fun gradientDrawable(): GradientDrawable {
return GradientDrawable().apply {
colors = intArrayOf(
Color.parseColor("#F0FFFF"),
Color.parseColor("#00BFFF"),
Color.parseColor("#89CFF0")
)
gradientType = GradientDrawable.LINEAR_GRADIENT
shape = GradientDrawable.RECTANGLE
setStroke(2,Color.parseColor("#2A52BE"))
}
}
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"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/rootLayout"
android:background="#DCDCDC" />


- android kotlin - BitmapShader example
- android kotlin - Bitmap tint solid color
- android kotlin - Drawable tint programmatically
- android kotlin - Set image from drawable
- android kotlin - Convert drawable to bitmap
- android kotlin - Create GradientDrawable 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 icon color
- android kotlin - Menu overflow icon
- android kotlin - Disable soft keyboard on NumberPicker