Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize the status bar of mobile phone interface by Android

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Android how to customize the mobile phone interface status bar, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.

Preface

We know that on IOS, the color of the status bar is always the same as that of the title bar of the app, and the user experience is very good, so can Android? Before Android 4.4, the answer was no, but after 4.4, Google allows developers to customize the background color of the status bar, which is a good experience! If you have the latest version of qq installed on your phone and your Android SDK version is 4.4 or above, you can see how it works:

It seems to have achieved the effect, but careful observation, as if the title bar has been raised, that is to say, the APP interface is full screen, the status is covered on the APP, well, this is not the effect we want, so how to start the interface from the lower part of the status bar, just add an attribute to the outermost control of the Activity layout file: Android:fitsSystemWindows= "true"! Take a look at the effect: this achieves our original style.

PS: some problems have been found during use. Using the above method works for a single Activity, but what about navigation pages that inherit TabActivity? If MainActivity inherits TabActivity,Tab1Activity, Tab2Activity, and Tab3Activity are three children, then the code for setting the status bar needs to be written in MainActivity, and android:fitsSystemWindows= "true" needs to be written in the xml layout file of the three sub-Activity. There is still a problem after setting, that is, there is no problem after entering the home page of the application, that is, Tab1Activity, while Tab2Activity and Tab3Activity do not achieve the effect. Their effect is equivalent to the effect without android:fitsSystemWindows= "true". At the beginning, I suspected that it was Activity for different reasons. Therefore, I adjusted the position of Tab1Activity and Tab3Activity. As a result, Tab3Activity became normal after the home page, but Tab1Activity was not normal again. I couldn't help it at last. I added a few lines of code to the OnCreate method of Tab2Activity and Tab3Activity:

If (Build.VERSION.SDK_INT > = Build.VERSION_CODES.KITKAT) {((LinearLayout) findViewById (R.id.ll)) .setPadding (0, SysUtils.getStatusHeight (this), 0pm 0);}

It means, first find out the height of the status bar, and then set the PaddingTopvalue of the outermost control to the height of the status bar, the result is just to achieve the effect, as for why only the home page Activity can achieve the effect, and the latter sub-items can not achieve the effect, I am also depressed, there are friends who know can share it! Status bar height algorithm:

/ * * status bar height algorithm * @ param activity * @ return * / public static int getStatusHeight (Activity activity) {int statusHeight = 0; Rect localRect = new Rect (); activity.getWindow () .getDecorView () .getWindowVisibleDisplayFrame (localRect); statusHeight = localRect.top If (0 = = statusHeight) {Class localClass; try {localClass = Class.forName ("com.android.internal.R$dimen"); Object localObject = localClass.newInstance (); int i5 = Integer.parseInt (localClass.getField ("status_bar_height") .get (localObject) .toString ()) StatusHeight = activity.getResources () .getDimensionPixelSize (i5);} catch (ClassNotFoundException e) {e.printStackTrace ();} catch (IllegalAccessException e) {e.printStackTrace () } catch (InstantiationException e) {e.printStackTrace ();} catch (NumberFormatException e) {e.printStackTrace ();} catch (IllegalArgumentException e) {e.printStackTrace () } catch (SecurityException e) {e.printStackTrace ();} catch (NoSuchFieldException e) {e.printStackTrace ();}} return statusHeight } after reading the above, have you mastered how Android can customize the status bar of the mobile phone interface? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report