I am creating a Java Android application using Android Studio. I created a custom toolbar to use instead of the default action bar via setSupportActionBar. Everything is working except my custom theme is not being applied to the toolbar at all. It is correctly being applied to everything else.
Here is the toolbar XML:
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="@color/baseLight"
android:elevation="4dp"
android:theme="@style/Base.Theme.BeatCube"
>
</androidx.appcompat.widget.Toolbar>
Here is the main activity XML that imports the toolbar:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="0dp"
tools:context="com.therealsamchaney.beatcube.MainActivity">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar"
/>
<LinearLayout
android:id="@+id/topLinear"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
tools:layout_editor_absoluteX="1dp"
app:layout_constraintTop_toBottomOf="@id/toolbar"
app:layout_constraintBottom_toTopOf="@id/grid_container"
tools:layout_editor_absoluteY="65dp">
<ToggleButton
android:id="@+id/recordPlayToggle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:checked="true"
android:text="Record/Play"
android:textOff="In Play Mode"
android:textOn="In Record Mode" />
</LinearLayout>
<FrameLayout
android:id="@+id/grid_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="@id/bottomLinear"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/topLinear">
<!-- app:layout_constraintDimensionRatio="1:1"-->
</FrameLayout>
<LinearLayout
android:id="@+id/bottomLinear"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
app:layout_constraintTop_toBottomOf="@id/grid_container"
app:layout_constraintBottom_toBottomOf="parent"
>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Here is the themes.xml file with the custom theme:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Base.Theme.BeatCube" parent="Theme.Material3.DayNight.NoActionBar">
<!-- Customize your light theme here. -->
<!-- <item name="colorPrimary">@color/my_light_primary</item> -->
<item name="android:textColor">@color/text</item>
<item name="android:windowBackground">@color/baseDark</item>
<item name="android:fontFamily">serif</item>
</style>
<style name="Theme.BeatCube" parent="Base.Theme.BeatCube" />
<style name="BeatCubeDialog" parent="Theme.AppCompat.Dialog">
<item name="android:textColor">@color/text</item>
<item name="android:windowBackground">@color/baseDark</item>
<item name="android:fontFamily">serif</item>
</style>
And here is the manifest file as well:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<application
android:name="com.BeatCube"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.BeatCube"
tools:targetApi="31">
<activity
android:name="com.therealsamchaney.beatcube.RecordActivity"
android:exported="false"
android:theme="@style/BeatCubeDialog"
/>
<activity
android:name="com.therealsamchaney.beatcube.MainActivity"
android:exported="true"
android:theme="@style/Base.Theme.BeatCube"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>