Android high-imitation QQ immersion status bar _android

Source: Internet
Author: User
Tags xmlns

Objective:

Before entering today's topic, or the old way to talk about feeling it, recently feel the whole lost sense of direction, good confused! Looking for a job has failed again, is Android really saturated? These two days I have not gone out, in addition to go downstairs to sell is curtilage dormitory, static thought for a long time, I still can't forget beginner's mind, I believe I can not find a job for many reasons, the most important thing is to be hard enough to do ah, run the child! Next I will tell you how to quickly create immersion status bar, although it feels a bit encounter, but in fact not finish!

One: What is immersion status bar?

The immersive status bar is a set of transparent system UI styles that Google has provided to our developers since Android 4.4, so that the style is given to the status bar and the navigation bar, so that you don't have to face the dark two black bars every day before. can also be adjusted to the same style as the activity, forming a complete theme, and IOS7.0 the same as the system.

Let me give you a comparison of the immersion and no immersion style effect chart, as shown in the following figure:

(Non-immersion)

(Immersion type)

I believe that we all understand what is immersed status bar, now open a lot of apps will have this effect, it is conceivable that the immersion status bar is quite practical!

Second, the use of immersion status bar high imitation QQ:

Steps to implement an immersion status bar are often simple: because the immersion status bar is Android4.4 after the introduction, first in the program to add a judgment, that is, when the system version is 4.4 or more than 4.4 can use the immersion status bar, and then set the status bar and navigation bar in the statement is transparent:

The Immersion status bar
if (Build.VERSION.SDK_INT >= build.version_codes) can be used when the system version is 4.4 or above 4.4. KitKat) {
 //transparent status bar
 GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
 Transparent navigation bar
 GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}

Finally, add the 、、、 in the layout file

Android:fitssystemwindows= "true"
android:cliptopadding= "true"

This will achieve the Immersion status bar!

It's so simple, it's so resistant! Source is the best mentor, look at the overall code now:

XML layout file:

<?xml version= "1.0" encoding= "Utf-8"?> <linearlayout xmlns:android= "http://schemas.android.com/apk/res/" Android "xmlns:tools=" Http://schemas.android.com/tools "xmlns:app=" Http://schemas.android.com/apk/res-auto "an" Droid:layout_width= "Match_parent" android:layout_height= "match_parent" android:background= "#ffffff" Android:or ientation= "Vertical" tools:context= ". Mainactivity "> <relativelayout android:fitssystemwindows=" true "android:cliptopadding=" true "Android:layout_ Width= "Match_parent" android:layout_height= "80DP" android:background= "#0099cc" > < De.hdodenhof.circleimageview.CircleImageView android:id= "@+id/img_head" android:layout_width= "40DP" android:layou t_height= "40DP" android:layout_gravity= "Center_horizontal" android:layout_margintop= "13DP" Android:layout_marginl eft= "15DP" app:civ_border_width= "2DP" app:civ_border_color= "#FFFFFF" android:src= "@mipmap/meinv" > </de.hd Odenhof.circleimageview.circleimageview> <textview android:id= "@+id/tv_title" android:layout_width= "Wrap_content" android:layou 
   t_height= "Wrap_content" android:layout_margintop= "26DP" android:layout_centerhorizontal= "true" android:text= "Contacts" Android:textcolor= "@android: Color/white" android:textsize= "18sp"/> <textview android:id= "@+id/tv_right_
   Add "android:layout_width=" Wrap_content "android:layout_height=" wrap_content "android:layout_margintop=" 26DP " android:layout_marginright= "15DP" android:layout_alignparentright= "true" android:text= "Add" android:textcolor= "@an Droid:color/white "android:textsize=" 18sp "/> </RelativeLayout> <textview android:layout_width=" match_p 
  Arent "android:layout_height=" match_parent "android:gravity= Center" android:text= "immersion status bar" android:textsize= "22SP" android:background= "#E0FFFF"/> </LinearLayout>

In mainactivity:

Package Com.zsml.chaotranstintbar;
Import android.app.Activity;
Import Android.os.Build;
Import Android.os.Bundle;
Import Android.view.Window;
Import Android.view.WindowManager;
public class Mainactivity extends activity{
 @Override
 protected void onCreate (Bundle savedinstancestate) {
  super.oncreate (savedinstancestate);
  This.requestwindowfeature (window.feature_no_title);
  Setcontentview (r.layout.activity_main);
  The Immersion status bar
  if (Build.VERSION.SDK_INT >= build.version_codes) can be used when the system version is 4.4 or above 4.4. KitKat) {
   //transparent status bar
   GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
   Transparent navigation bar
   GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
  }
 }
}

Other ways to implement immersion status bars: Dynamic joins, Third-party libraries.

1, dynamic implementation:

Dynamic implementation is also relatively simple, the first is to hide the layout, the last dynamic calculation of the status bar height and settings, are operating in the mainactivity, layout files do not have to add android:fitssystemwindows= "true", Android: Cliptopadding= "True" these two sentences!

So directly to the source code bar:

In mainactivity:

Import android.app.Activity;
Import Android.os.Build;
Import Android.os.Bundle;
Import Android.view.View;
Import Android.view.Window;
Import Android.view.WindowManager;
Import Android.widget.LinearLayout;
Import Java.lang.reflect.Field; public class Twoactivity extends activity {@Override protected void onCreate (Bundle savedinstancestate) {Super.oncre
  Ate (savedinstancestate);
  Remove the title this.requestwindowfeature (window.feature_no_title);
  Setcontentview (R.layout.activity_two); The Immersion status bar if (Build.VERSION.SDK_INT >= build.version_codes) can be used when the system version is 4.4 or above 4.4.
   KitKat) {//Transparent status bar GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
   Transparent navigation bar GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
   LinearLayout linear_bar= (linearlayout) Findviewbyid (R.id.linear_bar);
   Linear_bar.setvisibility (view.visible);
   int Statusheight=getstatusbarheight (); Linearlayout.layoutparams params= (linearlayout.layoutparams) linear_bar.getLayoutparams ();
   Params.height=statusheight;
  Linear_bar.setlayoutparams (params); /** * Gets the height of the status bar * @return/private int getstatusbarheight () {try {class<?> c=class.forname ("Co
   M.android.internal.r$dimen ");
   Object obj=c.newinstance ();
   Field Field=c.getfield ("Status_bar_height");
   int X=integer.parseint (Field.get (obj). toString ());
  Return Getresources (). getdimensionpixelsize (x);
  }catch (Exception e) {e.printstacktrace ();
 return 0; }
}

So it's done, is it as simple as that 、、、

2, third Party Library Implementation (Systembartint):

Systembartint is open source to the GitHub of an open source library to come;

Address: Https://github.com/jgilfelt/SystemBarTint

Use steps:

Association library: Compile ' com.readystatesoftware.systembartint:systembartint:1.0.3 '

Add in XML layout:

Android:fitssystemwindows= "true" android:cliptopadding= "true" mainactivity: Import android.app.Activity;
Import Android.os.Build;
Import Android.os.Bundle;
Import Android.view.Window;
Import Android.view.WindowManager;
Import Com.readystatesoftware.systembartint.SystemBarTintManager; public class Threeactivity extends activity {@Override protected void onCreate (Bundle savedinstancestate) {Super.onc
  Reate (savedinstancestate);
  This.requestwindowfeature (Window.feature_no_title);
  Setcontentview (R.layout.activity_three); The Immersion status bar if (Build.VERSION.SDK_INT >= build.version_codes) can be used when the system version is 4.4 or above 4.4.
   KitKat) {//Transparent status bar GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
   Transparent navigation bar GetWindow (). Addflags (WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
   Systembartintmanager Tintmanager = new Systembartintmanager (this);
   Activates the status bar tintmanager.setstatusbartintenabled (true); Enable navigation bar tint to activate the navigation bar Tintmanager.setnaviGationbartintenabled (TRUE);
   Set the system bar to set the color//tintmanager.settintcolor (r.color.red);
   Set the color Tintmanager.setstatusbartintresource (r.color.middle_color) to the status bar;
  Set the navigation bar to set resource Tintmanager.setnavigationbartintresource (R.color.androidcolore); }
 }
}

Are all the same, I personally think the first method is the best to achieve and understand, we can try, I hope to help you! Finally put out the immersion status bar-high imitation QQ effect chart is as follows:

The above is a small set to introduce the Android high imitation QQ immersion status bar, hope to help everyone, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.