The ActionBar is an important part of the Android user interface that provides users with easy access to key features and functions of an app. To make your app stand out, you may want to customize the appearance of the ActionBar. In this blog post, we'll explore how to change the background color, title text color, and title text size of the ActionBar in an Android Studio Kotlin project.
The ActionBar is an important part of the Android user interface that provides users with easy access to key features and functions of an app. To make your app stand out, you may want to customize the appearance of the ActionBar. In this blog post, we'll explore how to change the background color, title text color, and title text size of the ActionBar in an Android Studio Kotlin project.
To change the background color, title text color, and title text size of the ActionBar in an Android Studio, just add the following code in your MainActivity.kt file.
Imports
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.graphics.drawable.ColorDrawable
import android.text.Spannable
import android.text.SpannableString
import android.text.style.AbsoluteSizeSpan
import android.text.style.ForegroundColorSpan
import androidx.core.content.ContextCompat
MainActivity.kt
supportActionBar?.let { actionBar ->
actionBar.setBackgroundDrawable(ColorDrawable(ContextCompat.getColor(this, R.color.red)))
val title = SpannableString("My ActionBar Title")
title.setSpan(ForegroundColorSpan(ContextCompat.getColor(this, com.google.android.material.R.color.m3_ref_palette_white)), 0, title.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
title.setSpan(AbsoluteSizeSpan(24, true), 0, title.length, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
supportActionBar?.title = title
}
And done. Now run your app.