I want use custom toolbar because of title and subtitles but I also want to add overflow menu and I did everything and my toolbar doesn't showing overflow menu what I'm suppose to do
Main Activity Layout xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".BluetoothMain"
android:orientation="vertical"
tools:menu="@menu/bluetooth_overflow_menu">
<include
layout="@layout/bluetooth_toolbar"
android:visibility="visible"/>
</LinearLayout>
Custom action bar layout
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar 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/BluetoothToolBar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/yellowGreenColorWheel"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:title="Bluetooth"
app:subtitle="Not Connected"
tools:menu="@menu/bluetooth_overflow_menu">
</androidx.appcompat.widget.Toolbar>
Overflow menu, here I add Bluetooth icon and Action setting
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/action_favorite"
android:icon="@drawable/bluetooth_white_icon"
android:title="action_favorite"
app:showAsAction="ifRoom"/>
<!-- Settings, should always be in the overflow -->
<item android:id="@+id/action_settings"
android:title="Settings"
app:showAsAction="never"/>
</menu>
Build Gradle File minSdk = 28, tergetSdk = 32
android {
compileSdk 32
defaultConfig {
applicationId "com.indiebloog.IndieNode"
minSdk 28
targetSdk 32
versionCode 1
versionName "1.0"
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
namespace 'com.indiebloog.IndieNode'
}