-2

How to make the status bar to be transparent and hide the navigation bar?

For example,

enter image description here

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Jim
  • 91
  • 2
  • 12

3 Answers3

0

All you need to do is set these properties in your theme:

<item name="android:windowTranslucentStatus">true</item>

Your activity / container layout you wish to have a transparent status bar needs this property set:

android:fitsSystemWindows="true"

To hide navigation bar use this code on your activity onCreate()

View decorView = getWindow().getDecorView();
// Hide both the navigation bar and the status bar.
// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as
// a general rule, you should design your app to hide the status bar whenever you
// hide the navigation bar.
int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
              | View.SYSTEM_UI_FLAG_FULLSCREEN;
decorView.setSystemUiVisibility(uiOptions);
Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66
0

Select empty activity while creating new activity. Select empty activity while creating new activity.

If you just want a theme with no action bar you can use 'NoActionBar' variant, for eg. if your base theme is as below

<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

then you can use

<style name="AppThemeNoActionBar" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

But if you want to retain the properties of your main theme i.e. AppTheme you can do as below

<style name="AppThemeNoActionBar" parent="AppTheme">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

You can retain all the properties of your base theme this way and don't have to explicitly add them in your NoActionBar theme :)

0

in your style

   <style name="AppTheme.TransparentActivity">
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowBackground">@android:color/transparent</item>
    <item name="android:windowIsTranslucent">true</item>
    <item name="windowNoTitle">true</item>
   </style>

and in your manifest file

    <activity
        android:name=".MainActivity"
        android:theme="@style/AppTheme.TransparentActivity">
     </activity>
Saurabh Mistry
  • 12,833
  • 5
  • 50
  • 71