I'm following this tutorial on Youtube on how to create a navigation menu bar https://youtu.be/fGcMLu1GJEc
And I have this in my theme.xml file
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
but the AppTheme is in red and the application won't run I've checked many times and I just can't see where it could've gone wrong, the Youtube video is relatively old so perhaps it should be written in a different way with the newer version now?
CodePudding user response:
Have you specified the AppTheme in your theme.xml ? Make sure these 2 steps are completed
- You have a style named "AppTheme" in your theme.xml
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
</style>
- AppTheme.NoActionBar will only work if you've already added an AppTheme
Explaination :- AppTheme.NoActionBar means, you're using AppTheme that you've already added in a new theme and on top of it you're adding one more attribute that this AppTheme will not have any Action Bar.
<style name="AppTheme.NoActionBar" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<item name="android:textColor">@color/black</item>
</style>
CodePudding user response:
proper way to do this:
<style name= "Theme.projectName" parent="Theme.AppCompat.NoActionBar">
...//set styles
</style>
eg:
<style name="Theme.AppTheme" parent= "Theme.AppCompat.NoActionBar">
Now where ever you want to apply different properties for an element
<style name="name_of_style" parent="Theme.AppTheme">
...
</style>
eg:
<style name="AppNoActionBar" parent="Theme.Apptheme">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="toolbar_matrix" parent="Theme.AppTheme">
....
....
</style>