Android Tool bar with example-Kotlin

Default ToolBar

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ExToolBar"/>
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.ExToolBar" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>
</resources>
Theme.MaterialComponents.DayNight.NoActionBar

Customizing the Tool Bar

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">

<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/black"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
<style name="Theme.ExToolBar1" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="toolbarStyle">@style/ToolBarStyle</item>

</style>
<style name="ToolBarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:background">@color/black</item>
<item name="titleTextAppearance">@style/TitleTextAppearance</item>
<item name="subtitleTextAppearance">@style/SubTitleTextAppearance</item>
</style>

<style name="TitleTextAppearance" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<item name="android:textSize">28sp</item>
<item name="android:textColor">#38ADAE</item>
</style>

<style name="SubTitleTextAppearance" parent="TextAppearance.Widget.AppCompat.Toolbar.Subtitle">
<item name="android:textSize">14sp</item>
<item name="android:textColor">#00B7FF</item>
</style>
<androidx.appcompat.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:title="title"
app:subtitle="subtitle">

--

--

--

Mobile App Developer and Trainer

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Flutter Essentials: Forms

Exploring Dependency Injection in Android — Dagger, Koin, and Kodein

10 Flutter tips — season 2 — part 5/10

Android: Publish to Firebase Distribution via Gradle command

Advanced Search Filter in Android-search the substring.

Navigation in Feature Modules

Android Slices — 3W’s

The Genesis Order Free Download (v23044)

The Genesis Order Free Download (v23044)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Satheesh Guduri

Satheesh Guduri

Mobile App Developer and Trainer

More from Medium

Room Database using ViewModel and live data-Kotlin-Part 2.

Hello World! With Android Studio

Novice Note: HMS Core Integration to Android Studio in Ubuntu 21.10

Creating Home Channel on Android TV