How can I remove the status bar in android studio? - android

So basically I want to remove the status bar of my app and I've found no solution. I don't want to make my app fullscreen I just want that part to be transparent and have more space for my app. I tried changing the color of the status bar to transparent but nothing works. Any help would be appreciated! I will attach a photo with the part that I want to remove to be more specific.
https://i.stack.imgur.com/Zw5Tk.png

if you don't want to make your app full screen, you should make the status bar transparent. So add this line to your theme.xml file:
<item name="android:windowTranslucentStatus">true</item>
Therefore, your theme.xml should be something like this:
<resources>
<style name="Theme.MyApp" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:windowTranslucentStatus">true</item>
</style>
</resources>

You can use WindowInsetsControllerCompat API to acheive this
You can try this function . Add this in onCreate() of activity.
private fun hideStatusBar() {
WindowCompat.getInsetsController(window,window.decorView).apply {
systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
hide(WindowInsetsCompat.Type.statusBars())
}
}
Click here to read more

Related

Android: windowLightNavigationBar not working

Background: My background is in web development, ruby and javascript. I'm working on a mostly react-native app, so very likely I'm missing something basic.
What I want
android navigation bar to be white with dark system buttons see image in link white navigation bar
My Current Code
res/values/style.xml
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:windowTranslucentNavigation">false</item>
<item name="android:navigationBarColor">#FFFFFF</item>
</style>
</resources>
What is happening instead
The background AND the buttons are white. which is not so great for UX.
** What I have Tried **
this is what got me where I am now Change navigation bar icon color on Android
I have tried putting style.xml in a values-v27 folder.
I just worked on this same topic and found out you need to run at least Android 9.0 (or API level 28) on the device/emulator for this to work.
Also, I had to add this to the color of the bar:
<item name="android:navigationBarColor">#android:color/white</item>
So, recommended steps:
Create a values-v28 folder
Insert the style:
<item name="android:navigationBarColor">#android:color/white</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowLightNavigationBar">true</item>
In your other values folder, you kind of have to live with the fact that this windowsLightNavigationBar doesn't apply...
Small remark
I also found a bug on this change, when putting app in background and then opening it again, the navbar buttons stay white for a second before getting the dark color
Your code is working as intended for me. Make sure you have the file name and file path written correctly:
https://imgur.com/xclYDuZ
A new approach would be:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.navigationBarColor = ContextCompat.getColor(this, android.R.color.white)
WindowInsetsControllerCompat(window, window.decorView).isAppearanceLightNavigationBars = true
}

How to create a fully transparent Navigation Bar?

I want to change the Navigation Bar fully transparent like on the picture below.
I tried <item name="android:windowTranslucentNavigation">true</item> but it is not fully transparent (more like 50%).
Is there a solution? Because i found nothing to it, but I saw some apps that used it like Nova. And its even in googles guidelines https://material.google.com/layout/structure.html#structure-system-bars
I was inspired by Google Keep app, which have similar implementation like shown below:
So i tried to find a proper post on how to achieve this thing but unfortunately found nothing and also above answers weren't working. So i decided to try out all the flags related to navigationBar Android Studio was suggesting.
Let me explain in detail:
Only android:navigationBarColor won't do any thing when you are using a light theme. But on dark theme, it will work.
Setting windowTranslucentNavigation to true will do 2 things:
draw the activity below the soft navbar
override navigationBarColor and force it to be transparent.
Which will look like below image:
If you use FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS (follow #Frankenxtein's answer) you will get below result:
Which is somehow close to desired result, but it isn't because it draws activity components below navbar. And also it mess your padding and margin (see full screenshot here). And more, you have to do it for each activity and also have to adjust current margin.
The Solution
This can be achieved without compromising current layout. To do this in Dark theme, you have no issue, just setting android:navigationBarColor will do the work.
However our goal here is to do it with a light theme let (#FFFFFF). Using android:windowLightNavigationBar which requires API 27 or higher along with android:navigationBarColor will result what we want.
<item name="android:navigationBarColor">#color/colorPrimaryDark</item>
<item name="android:windowLightNavigationBar">true</item>
Here for my app case colorPrimaryDark is #FFFFFF in light theme and dracula in dark theme, you can also declare a new variable for this. Which yields below results:
Light Theme
Dark Theme
Here android:navigationBarColor is setting background colour of navbar. And android:windowLightNavigationBar setting dark button colours and indicates that background is light as you can understand from it's name.
Hope this helps !
use following code in onCreate of your Activity:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Window w = getWindow(); w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
and in your styles.xml:
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:windowTranslucentNavigation">false</item>
Since no one has mentioned this and I spent too much time trying to figure it out on my own. A solution for API 29+ to make the system bars fully transparent regardless of anything:
<item name="android:enforceNavigationBarContrast">false</item>
<item name="android:enforceStatusBarContrast">false</item>
You can achieve that using FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS. Documentation explains:
Flag indicating that this Window is responsible for drawing the
background for the system bars. If set, the system bars are drawn with
a transparent background and the corresponding areas in this window
are filled with the colors specified in getStatusBarColor() and
getNavigationBarColor().
Set it like that in your Activity's onCreate:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
Try this
<resources>
<style name="Theme" parent="android:Theme.Material.Wallpaper.NoTitleBar">
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
It worked for android >= 10
You can try the color by default color android
<item name="android:navigationBarColor">#android:color/transparent</item>
<item name="android:windowLightNavigationBar">true</item>
<item name="android:windowTranslucentNavigation">true</item>
By the way you can try this
<item name="android:fitsSystemWindows">true</item>
<item name="android:statusBarColor">#android:color/transparent</item>
<item name="android:navigationBarColor">#android:color/transparent</item>

Navigation drawer toggle padding

I'm using appcompat v7 with the hamburger to arrow toggle.
However, I would like to add some padding on the left of the toggle.
This is my current situation :
http://nl.tinypic.com/r/2a0f712/8
This is what I would like to have :
http://nl.tinypic.com/r/v3q176/8
I've tried this :
findViewById(android.R.id.home).setPadding(25, 0, 15, 0);
But that didn't work. However, this did add padding on the right of the toggle.
I've also tried to add padding in the styles but that didn't work either.
AFAIK, the action is hard-coded in layout resources. U cant change the padding. Google did this to maintain the consistency across the app guess.
However u can define ur own icon in a drawable with ur own attributes (padding and all) and use it as an indicator by adding this line to styles.xml
<item name="android:homeAsUpIndicator">#drawable/xyz</item>
And the image u have shown about what u want is actually a toolbar and not an action bar. In toolbar, the icon is by default placed there.
To know more about toolbar and how to implement them, here is a link : http://android-developers.blogspot.in/2014/10/appcompat-v21-material-design-for-pre.html
I'm going to assume you are familiar with styling to some extent and recommend you go that route. FYI I have not confirmed the code below as working but I think it would be close to what you want.
For res/values-14/style.xml, something like this:
<!-- style for Action Bar -->
<style name="MyPaddedActionBar" parent="android:style/Widget.Holo.Light.ActionBarView">
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>
And then for everything 14 and below, you would use AppCompat (res/values-14/style.xml):
<style name="MyPaddedActionBar" parent="#style/Theme.AppCompat.Light.DarkActionBar">
<item name="android:paddingLeft">32dp</item>
<item name="android:paddingRight">32dp</item>
</style>

Get rid of blue line

With the help of ActionBarSherlock I try to get my app running on pre 3.0 devices. There is a blue divider in the action bar, which I want to have removed.
I figured out that it isn't a divider, but part of the background graphic of the action bar. To get rid of the blue line I decided to override the background like this:
<style name="MyActionBar" parent="android:Widget.Holo.ActionBar">
<item name="android:background">#drawable/black</item>
<item name="background">#drawable/black</item>
</style>
I also set the background in the Java code:
getSupportActionBar().setStackedBackgroundDrawable(this.getResources().getDrawable(R.drawable.black));
As a result the blue line disappears on 4.x devices, but is still visible on 2.3.x devices. How do I get rid of the blue line on 2.3.x devices?
Stupid mistake: I used setStackedBackgroundDrawable instead of setBackgroundDrawable. It works fine with setBackgroundDrawable. This is the correct method to set the background of the action bar. setStackedBackgroundDrawable sets the background of the tab bar.
Seems that the blue line is part of the TabWidget you have there... But if it isn't you can have a look at this webpage: http://jgilfelt.github.io/android-actionbarstylegenerator/
It's a really good Action Bar style generator. Worth a try :)
actionBarDivider attribute belongs to the theme
Remove it like this:
<style name="AppTheme" parent="Theme.Sherlock">
<item name="android:actionBarDivider">#null</item>
</style>

Custom title bar still shows original on startup

I'm using a custom title bar in my app and it all works fine except that when the app starts up, the original (standard) android title bar is shown for a brief time before it is replaced by my custom title bar.
This is not a problem when the app is already loaded in memory because the 'delay' is not apparent but if the app is not already in memory, it is very obvious.
There's nothing special about the code :
requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);
setContentView(R.layout.main);
getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.window_title);
I thought about changing the style to have no window title and just include my custom title in the top of the layout but that doesn't seem right.
Thanks for any pointers.
Thomas Devaux has posted a smart solution. It worked in my app
Change the windowTitleBackgroundStyle to use color “#android:color/transparent”.
Also create a style for the text “android:windowTitleStyle” and set its “android:textColor” >to transparent as well.
For completeness to Lluis' answer, here's the full code you need to hide the default-title before the custom-title is initiated:
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<style name="CustomWindowTitleStyle">
<item name="android:textColor">#android:color/transparent</item>
</style>
<style name="CustomTheme" parent="#android:style/Theme.Holo">
<item name="android:windowActionBar">false</item>
<item name="android:windowTitleBackgroundStyle">#android:color/transparent</item>
<item name="android:windowTitleSize">50dp</item>
<item name="android:windowTitleStyle">#style/CustomWindowTitleStyle</item>
</style>
</resources>
add a splash screen activity before the main activity loads, should have enough time for the next one to load properly
Are you able to use an app theme to set a custom title globally for your app? See here for a pretty good example. I had a similar problem and i seem to remember going this route fixed it.

Categories

Resources