Sunday, June 14, 2020

android kotlin - Display logo on ActionBar

MainActivity.kt

package com.cfsuman.kotlintutorials

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 {
            // Set the action bar title
            title = "  Display Logo On ActionBar"

            // Action bar more settings to display logo
            setDisplayShowHomeEnabled(true)
            setDisplayUseLogoEnabled(true)

            // Set the icon to show as logo on action bar
            setLogo(R.drawable.ic_action_help)
        }
    }
}
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" />