NoActionBar still displaying on physical devices - android

So here is my problem : I put NoActionBar on my themes and when i run my app in an emulated device no action bar are shown (so everthing is fine) BUT when I install and run the app on my smartphone (galaxy S8 API 28 if it has anything to with it) an action bar is still displaying why so?
Here is the themes.xml file :
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.DTTREALESTATE" parent="Theme.MaterialComponents.DayNight.NoActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/light_gray</item>
<item name="colorOnPrimary">#color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/red</item>
<item name="colorOnSecondary">#color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor">#color/light</item>
<!-- Navigation bar color -->
<item name="android:navigationBarColor">#color/light</item>
</style>
</resources>
I tried to use the DarkActionBar to see what would be display on my smartphone but it didn't do anything it only affect the emulated devices... To be honest I have ABSOLUTLY no idea how to solve this.

Please add these lines in both of themes.xml files (Day and night).
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>

Don't forget to change it in both (night and normal one)themes.xml files

Related

How do you change android app theme colors with default phone settings?

I'm new to android styles and themes, and I've looked at a a lot of different posts that don't seem to fix the problem I'm facing.
The solutions I've tried all seem to look almost identical to this one (usually not including the physical in-app switch), so it's possible I'm just missing something here!
Basically, I want the background of the app I'm developing to switch between light and dark colors depending on the setting of the phones default dark mode setting. So if the phone is in dark mode, the darker colors apply when you open the app, and if it's in light mode the lighter colors get applied.
To be clear, I'm talking about the light/dark mode that you set in your phone settings or slide down screen, not a switch within the app.
I have switched both the style's and theme's parents to use dayNight.
Quick note
the style's name is currently LightTheme, that's just from me experimenting with different things to try and get it working!
styles.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="LightTheme" parent="Theme.MaterialComponents.DayNight">
<item name="colorPrimary">#color/light_blue</item>
<item name="colorPrimaryDark">#color/dark_blue</item>
<item name="colorSecondary">#color/dark_purple</item>
<item name="colorSecondaryVariant">#color/light_purple</item>
<item name="colorAccent">#color/yellow</item>
<item name="colorButtonNormal">#color/orange</item>
</style>
</resources>
Themes.xml
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.Whereshouldieat" parent="Theme.MaterialComponents.DayNight">
<!-- 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>
I can set themes or styles for the whole app or activity, but I don't want the background of smaller children elements to have the same color background as the very "back" of the app (for example, I don't want recyclerview items to share a background color with the background of the app, because then they don't stand out like I need them too). I can set the style of the views, but then they don't change with the light/dark mode of the phone.
currently I have the colors changing with what seems like an incorrect workaround to the problem, which is this piece of code in
MainActvitiy.kt
when (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) {
Configuration.UI_MODE_NIGHT_NO -> {
val backgroundColor = ContextCompat.getColor(this, R.color.light_blue)
findViewById<ConstraintLayout>(R.id.main_activity_layout).setBackgroundColor(backgroundColor)
}
Configuration.UI_MODE_NIGHT_YES -> {
val backgroundColor = ContextCompat.getColor(this, R.color.black)
findViewById<ConstraintLayout>(R.id.main_activity_layout).setBackgroundColor(backgroundColor)
}
}
What I CAN do, is have the app switch between a white and black background using the day or night mode as I'm describing. Is it as easy as just changing the default colors for these "modes"? If so, I just need to know how to do that!
I appreciate any help, thank you!!
Please checkout this code lab Add Light/Dark Theme
Update the dark version of your theme
Open themes.xml (night) (app > res > values > themes > themes.xml (night))
Note: This themes.xml file is different from the previous themes.xml file.
This file contains the dark theme version of the theme.
The resources in this file will be used when Dark theme on the device is on.
When you're done, your themes.xml (night) file should look like this:
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Application theme for dark theme. -->
<style name="Theme.TipTime" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">#color/green_light</item>
<item name="colorPrimaryVariant">#color/green</item>
<item name="colorOnPrimary">#color/black</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">#color/blue_light</item>
<item name="colorSecondaryVariant">#color/blue_light</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>
your theme structure should look like this

Status bar icons color in vertical Multi-window Mode if the app window is in the second position

When in multi-window mode if the app window is in the second position, status bar icons color change their tint from white to black from time to time (if you rotate the phone) on Android 10 Lineage OS. There's no such bug on Samsung Stock running Android 9. It looks like android randomly gives priority to color scheme of the app in the first position.
Correct behavior:
Incorrect behavior:
styles.xml:
<resources>
<!-- 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>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>
</style>
</resources>
Full source code is available at https://github.com/alecpetrosky/Android-Immerse-Demo
It seems that rotation also makes Android to redraw status bar. Setting automatic recreation of Activity on configuration changes solved the problem.

How to hide Action Bar in Android Studio 4.1?

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.

Remove action bar shadow

I want to remove the shadow that appears below the appcompat action bar so that the background of the action bar is completely transparent.
This is my theme and action bar style:
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<!-- 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:actionBarStyle">#style/TransparentActionBar</item>
<item name="android:windowActionBarOverlay">true</item>
<!-- Support library compatibility -->
<item name="actionBarStyle">#style/TransparentActionBar</item>
<item name="windowActionBarOverlay">true</item>
</style>
<!-- Transparent Action Bar Style -->
<style name="TransparentActionBar"
parent="Widget.AppCompat.Light.ActionBar.Solid.Inverse">
<item name="android:background">#android:color/transparent</item>
<!-- Support library compatibility -->
<item name="background">#android:color/transparent</item>
<item name="elevation">0dp</item>
</style>
My minimum API level is 16
I've tried several solutions for this including:
Setting elevation to 0dp only works for Lollipop devices.
I get a "resource not found" error if I try to use windowContentOverlay
Setting the background of the root view to a color like white or transparent doesn't work
I've been trying to get this to work on 4.4.4 to no avail. Is it not possible below API level 21?
EDIT:
it turns out that the windowContentOverlay only works with the android prefix:
<item name="android:windowContentOverlay">#null<item/>
Trying to also define it without the prefix results in the resource not found error (this error points to the one with the prefix for whatever reason). I honestly don't understand why this occurs. I can only assume appcompat doesn't support the windowContentOverlay attribute.
Set windowContentOverlay to a drawable that will be drawn under the action bar. If you don't want a shadow set it to null, like so:
<item name="android:windowContentOverlay">#null</item>
and
<item name="windowContentOverlay">#null</item>
This works API level 16 and up.

Android: defining action bar style for a device running KitKat

I am defining action bar styles for an Android device running 4.4.2. I've tested the styles on a device running 4.3 and they work prefectly. The phone running KitKat however refuses to apply any of the rules defined by the style. I've defined the same theme in all three folders: values, values-11 and values-14.
<style name="AppTheme" parent="#style/Theme.AppCompat.Light">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:actionBarStyle">#style/MyStyledActionBar</item>
</style>
<style name="MyStyledActionBar" parent="#style/Widget.AppCompat.Light.ActionBar">
<!-- Setting values in the android namespace affects API levels 14+ -->
<item name="android:background">#drawable/oc_actionbar_background</item>
<item name="android:titleTextStyle">#style/MyActionBarTitleText</item>
<item name="android:actionMenuTextAppearance">#style/MyActionBarMenuText</item>
<item name="android:actionMenuTextColor">#style/MyActionBarMenuText</item>
<item name="android:actionOverflowButtonStyle">#style/MyActionButtonOverFlow</item>
<item name="android:displayOptions">showHome</item>
</style>
<style name="MyActionBarTitleText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">#696969</item>
</style>
<style name="MyActionBarMenuText" parent="#style/TextAppearance.AppCompat.Widget.ActionBar.Menu">
<item name="android:textColor">#696969</item>
</style>
<style name="MyActionButtonOverFlow" parent="#style/Widget.AppCompat.Light.Base.ActionButton.Overflow">
<item name="android:src">#drawable/ic_action_search</item>
</style>
I've also added
android:theme="#style/AppTheme"
to the manifest application tag. But the styles are still not applied. I have however managed to change the action bar properties at runtime (changing the color), but that's not a desirable way of handling such problems.
If anyone could advise me on the matter, I would be most grateful.
To prevent these kind of issues, I like to use the following tool to generate the style for me: http://jgilfelt.github.io/android-actionbarstylegenerator/
Easy to use tool that generates the style just like I want it. Might help you too, since you avoid these issues. Just paste this in your project, and you're done.
Other tools can be found here: http://romannurik.github.io/AndroidAssetStudio/index.html

Categories

Resources