With Android Q it seems the back button is gone.
In my app the backbutton is essential to navigating.
Do I need to implement my own button for Android Q and above?
Old devices looks like this. There is the hardware button:
New devices looks like this:
New with Android Q you don't have it. You need to swipe from right to left at the very right. Lots of users don't like that and lots of users from old generation will just not use an app, which they see as buggy. A User needs to confugre a special gesture to get back the button and you still don't see it.
We cannot force the user to do any special configuration to get back the button.
So my question is. Should all apps, which depending on this back-button as it was before implement an own back button?
updated question:
Thanks for mentoining appthemes. But still don't get it. My teststyle looks like this. What should I change now to get back the backbutton?
<resources xmlns:tools="http://schemas.android.com/tools">
<!-- Base application theme. -->
<style name="Theme.BackbuttonTest" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- 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>
Related
I know it sounds duplicate but it is not.
I have read a whole article about implementing what I want at android studio official site but no help.
My goal is to draw behind the system bars like this photo: ( I also want the hide the system bars which in this picture does not happen )
In other words I want to open my app in an immersive/fullscreen mode which is required in almost every app.
But whenever I try to draw behind the status bar (the bar that shows notification and battery etc.), the status bar and its items reveal themselves meaning the content I drew behind the status bar is obscured by the content of the status bar.
and whenever I try to hide the status bar, my content do not appear behind it. it is like a paradox.
To draw behind the system bars I use this method, as the above link suggests:
WindowCompat.setDecorFitsSystemWindows(getWindow(), false);
To hide the system bars I use this:
windowInsetsController.hide(WindowInsetsCompat.Type.systemBars());
But whenever I do each of them, it undoes the other one.
Fixed here. Just needed to handle devices with cutouts.
hello #YoloWex you just need to use a Fullscreen theme in your app theme style.xml and make sure the "android:windowFullscreen" is set to true
<style name="Theme.myApp" parent="Theme.AppCompat.Light.NoActionBar.FullScreen">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">#null</item>
<!-- 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>
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
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
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.
If you open Google Calendar on a phone running Android 10 (or later, presumably), you'll see the affordance for the ability to swipe up from the bottom of the screen is still there as a grey bar, but it's rendered over the top of the activity itself.
On my own app, however, this navigation bar at the bottom (if indeed that's what it is) has a grey background and my activity presumably stops at the top of it.
How do I do what Google Calendar has done?
add this line to your app theme:
<item name="android:statusBarColor">#color/colorPrimary</item>
like:
<style name="MainActivityTheme" 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:statusBarColor">#color/colorPrimary</item>
<item name="android:windowLightStatusBar" tools:ignore="NewApi">false</item>
</style>