How to hide Action Bar in Android Studio 4.1? - android

I am using Android Studio 4.1 and I want to hide the Action Bar. I searched stack overflow, but it seems there are some new methods introduced in Android Studio update of October 2020 since getActionBar().hide(); line method no longer works and app directly crashes. For more clarity, I created a new Project and added nothing else except the getActionBar().hide(); in the onCreate() method. Still the app crashes. My emulator is running on API 30, Android 11 on Pixel 3.
Kindly help.

It doesn't depend by Android Studio.
Since you are using a AppCompatActivity and you have to use getSupportActionBar() instead of getActionBar().
As alternative you can use a .NoActionBar theme, for example.
<style name="AppTheme" parent="Theme.MaterialComponents.DayNight.NoActionBar">
...
</style>

If my understanding is correct you don't want action bar any more.then if you are using old base android theme then you can change into this.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
or if you using new material design then you can change into.
<!-- Base application theme. -->
<style name="Theme.TextOverlayDemo" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- 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>
Thank you, feel free to ask doubts.

Related

When trying to use the material theme on Android, my title bar is not using the primary colour

From my research, it appears that when using the material theme on Android the title bar should take on the primary color but for me, it stays black. I know the theme itself is working as things did change to black when I first applied the default(dark) theme. I have this set in the styles.xml file:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style>
</resources>
The colors referenced from colors.xml are working as they show up on the s the de in android studio.
I have tried looking for a way to manually change the title bar but I have only found ways to do it programatically and not through layout files. I have attached a pic of what the title bar currently looks like and what i would like it to look like below:
Current title bar
What I want it to look like
Change it to
<style name="AppTheme" parent="android:Theme.Material">
<!-- Customize your theme here. -->
<item name="android:colorPrimary">#color/colorPrimary</item>
<item name="android:colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="android:colorAccent">#color/colorAccent</item>
<item name="android:statusBarColor">#color/colorPrimaryDark</item>
</style>

Textview background color got changed after adding custom theme to android app

My app interface originally looked like this. "my name" is a TextView and "my button" is a button which has an image as the background. Minimum sdk is 16.
I changed the action bar color of the app by adding a custom theme. I used the code below.
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:actionBarStyle">#style/MyTheme</item>
<!-- Customize your theme here. -->
</style>
<style name="MyTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#color/com_facebook_blue</item>
</style>
Then my output came like this.
All the background color got changed to the new color of the app. I only need to change the color of the action bar.
Can anyone help me?
Try this
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>

How to use android:Theme.Material (Material theme) in styles.xml android?

In my application, I am trying to implement android:Theme.Material as a parent theme in styles values-21 folder:
<!-- res/values-21/styles.xml -->
<resources>
<!-- your theme inherits from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- theme customizations -->
<item name="android:colorPrimary">#color/primary</item>
<item name="android:textColorPrimary">#color/text_primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">#color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">#color/accent</item>
<item name="android:navigationBarColor">#color/primary_dark</item>
</style>
</resources>
After running the app, I am getting below error
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
In values folder. I have below style
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- Customize your theme here. -->
</style>
But, if I add the same Theme.AppCompat.Light in values-21 folder its working fine. but actionbar color is not changing.
Why can't i use the material design theme in values-21 folder?
How to solve this problem?
(note: my application minsdk verison is 13 and maxsdk version is 22)
My activity extends AppCompactActivity
Your app theme is defined in the manifest file:
<application
android:theme="#style/AppTheme">
You will find this style defined in /res/values/styles.xml.
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#color/colorPrimary</item>
<item name="colorPrimaryDark">#color/colorPrimaryDark</item>
<item name="colorAccent">#color/colorAccent</item>
</style>
Using AppCompat allows your themes to be used even for devices older than Android 5.0. The main Material Design Themes are shown below.
Dark Theme
Light Theme
Light Theme with Dark Action Bar
Further Reading
Using the Material Theme (Android docs)
If your are using an AppCompatActivity, just use only a style in your res/values/styles.xml, and check the namespace that your are using for colorPrimary, colorPrimaryDark....
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">#color/primary</item>
<item name="colorPrimaryDark">#color/primary_dark</item>
<item name="colorAccent">#color/accent</item>
</style>

How to set background color of android app and background of action bar

I am trying to modify my app to have a dark blue action bar with a light blue background. So far I have only been able to make the entire app dark blue. How can I modify my code to keep the action bar the color it is now but make the background with the team numbers a light blue? Please note my apps minimum API is 14.
I am currently using the following code in my styles.xml:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:background">#color/teamLightBlue</item>
</style>
<!-- Activity themes -->
<style name="Theme.Base" parent="android:Theme.Light" />
<style name="Theme.Sample" parent="Theme.Base" />
<!-- the theme applied to the application or activity -->
<style name="CustomActionBarTheme"
parent="AppTheme">
<item name="android:actionBarStyle">#style/MyActionBarTheme</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBarTheme" parent="#android:style/Widget.Holo.Light.ActionBar">
<item name="android:background">#color/teamDarkBlue</item>
</style>
If you choose to use Theme.AppCompat, you can change Action Bar's background color using:
<item name="colorPrimary">#ffffff</item>
but if you choose the Holo one, you can change that color using
<item name="android:colorPrimary">#ffffff</item>
Hope this helps.
As far as I know your code is good instead of Widget.Holo.Light.ActionBar as its not part of AppCompat v7. Use this instead
<style name="CustomActionBarTheme" parent="AppTheme">
<item name="android:actionBarStyle" tools:ignore="NewApi">#style/MyActionBarTheme</item>
<item name="actionBarStyle">#style/MyActionBarTheme</item>
</style>
<style name="MyActionBarTheme" parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/teamDarkBlue</item>
<item name="background">#color/teamDarkBlue</item>
</style>
It should work fine!

Setting custom action bar colors

I am writing my first app using Android Studio 1.02 and following an on-line tutorial. In the build.gradle file I have minSdkVersion 15. I'm having a problem with setting custom action bar colors.
As per the instructions I tried setting the theme in the manifest at the application level with android:theme="#android:style/Theme.Holo.Light". The program would compile but not run on my phone (Android 4.4.2). After reading threads on this forum and else where I was never able to resolve this, but the tutorial showed how to point to custom theme with android:theme="#style/CustomActionBarTheme">
This worked, but not entirely. Below is my custom theme and colors value xml. The colors are all the same on purpose, for testing. The background color works, but the text shows up as white, no matter what values I put in there.
The other thing I had to do here to get this to compile was change all of the parent= references from parent="#style/Widget.Holo.ActionBar.TabText" to parrent="android:Widget.Holo.ActionBar.TabText"
Any help is appreciated.
Greg
<style name="CustomActionBarTheme"
parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:actionBarStyle">#style/MyActionBar</item>
<item name="android:actionBarTabTextStyle">#style/MyActionBarTabText</item>
<item name="android:actionMenuTextColor">#color/actionbar_text</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/MyActionBar</item>
</style>
<!-- ActionBar styles -->
<style name="MyActionBar"
parent="#style/Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#color/actionbar_background</item>
<!-- Support library compatibility -->
<item name="background">#color/actionbar_background</item>
</style>
<!-- ActionBar title text -->
<style name="MyActionBarTitleText"
parent="android:TextAppearance.Holo.Widget.ActionBar.Title">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<!-- ActionBar tabs text styles -->
<style name="MyActionBarTabText"
parent="android:Widget.Holo.ActionBar.TabText">
<item name="android:textColor">#color/actionbar_text</item>
</style>
<color name="disabled_text">#9FFF</color>
<color name="actionbar_background">#b43004</color>
<color name="background">#b43004</color>
<color name="actionbar_text">#b43004</color>

Categories

Resources