Home>

Full adaptation of the status bar

The status bar specifies the location on the top of the android phone where the phone status information is displayed.

The transparent status bar is a newly added feature in Android since 4.4.It can be the status bar defined according to the color we want,Enable titlebar to be integrated with status bar,Increase immersion.

We need to adapt the statusbar to different versions. Let ’s look at them one by one.

values ​​/styles.xml

<resources>
  <style name="theme.apptheme.translucentstatusbar" parent="theme.appcompat.light.noactionbar" />
</resources>

values-v19/styles.xml

<resources>
  <style name="theme.apptheme.translucentstatusbar" parent="theme.appcompat.light.noactionbar">
    <item name="android:windowtranslucentstatus">true</item>
  </style>
</resources>

values-21/styles.xml

<resources>
  <style name="theme.apptheme.translucentstatusbar" parent="theme.appcompat.light.noactionbar">
    <item name="android:statusbarcolor">@android:color/transparent&/item>
  </style>
</resources>

values-23/styles.xml

<resources>
  <style name="theme.apptheme.translucentstatusbar" parent="theme.appcompat.light.noactionbar">
    <item name="android:statusbarcolor">@android:color/transparent&/item>
    <item name="android:windowlightstatusbar">true</item>
  </style>
</resources>

Specific use

public class imagepreactivity extends appcompatactivity {
  @override
  protected void oncreate (bundle savedinstancestate) {
    super.oncreate (savedinstancestate);
    if (build.version.sdk_int>= build.version_codes.lollipop) {
      findviewbyid (android.r.id.content) .setsystemuivisibility (
          view.system_ui_flag_layout_fullscreen | view.system_ui_flag_layout_stable);
    }
    setcontentview (r.layout.activity_image_pre_layout);
  }
}
<activity
  android:name=". imagepreactivity"
  android:theme="@ style/theme.apptheme.translucentstatusbar" />

display effect

4.3 or less

4.4

5.0

6.0

  • Previous Idea mybatis example to configure log4j to print sql statements
  • Next MongoDBNet tool library MongoRepository use method detailed