Use of the Android:fitssystemwindows property

Source: Internet
Author: User

Property Description

The Fitssystemwindows property allows the view to adjust its layout according to the system window, simply to say whether we consider the layout of the system when setting up the application layout, where the system window includes the system status bar, navigation bar, input method, etc., including the bottom virtual keys of some mobile phone systems.

Android:fitssystemwindows= "true" (triggers the view's Padding property to allow space for the system window)
This property can be given any view setting, as long as all other padding properties of this view are invalidated, and the property is valid only if the transparent status bar (StatusBar) or the navigation bar (Navigationbar) is set.

Note: Fitssystemwindows only works on systems with Android4.4 and above, because the system StatusBar below 4.4 is not transparent.

Application Scenarios

In different Android versions, the app status bar and the system itself in different versions of the status bar adaptation;
Compatible with mobile phone systems with bottom virtual keys.

Property uses 1. Default Effect

Put one first. Test layout when the System status bar and navigation bar are not transparently set:

2, the System window after the effect of transparency

When the transparent status bar (StatusBar) and transparent navigation bar (Navigationbar) are set:

Transparent status bar code settings:

//布局设置<item name="android:windowTranslucentStatus">true</item>//或者代码设置if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);}

Transparent navigation bar code settings:

//布局设置<item name="android:windowTranslucentNavigation">true</item>//或者代码设置if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);}

In either case, our status bar (StatusBar) or navigation bar (Navigationbar) becomes transparent, and the layout expands to the location of StatusBar or Navigationbar.

Note: Here is a question about the status bar and the navigation bar transparent style, this is determined by the Android version, 4.4 Less transparent effect, 4.4~5.0 is fully transparent, more than 5.0 is translucent. I'm using 5.0 or more versions of the simulator to test, so it's translucent.

3. Set Fitssystemwindows property after effect

Now it's time for our key Fitssystemwindows property to appear, as long as the android:fitssystemwindows= "true" effect is added to the root layout, such as:

When the android:fitssystemwindows= "true" property is set, a value equal to the status bar height is automatically added to the transparent status bar paddingtop The system navigation bar for transparency automatically adds a value equal to the height of the navigation bar Paddingbottom

Code to paste the layout:

<?xml version= "1.0" encoding= "Utf-8"?><LinearLayoutXmlns:android="Http://schemas.android.com/apk/res/android"Android:layout_width="Match_parent"android:layout_height="Match_parent"Android:fitssystemwindows="True"android:orientation="Vertical" ><TextViewAndroid:layout_width="Match_parent"android:layout_height="45DP"Android:background="#66FF4081"android:gravity="Center"android:text="App title bar"Android:textsize="30sp"/><TextViewAndroid:layout_width="Match_parent"android:layout_height="0DP"android:layout_weight="1"Android:background="#0CE3EE"android:gravity="center" android:text="app content section" android:textsize="30sp"/> <TextView android: Layout_width= "match_parent" android:layout_height="45DP" android:background="#4188F8" android:gravity= "Center" android:text="app navigation bar" android:textsize="30sp"/>  </linearlayout>              

Chase and

Attach a Get status bar StatusBar and a Java code to get the Navigationbar height of the navigation bar:

//返回值就是状态栏的高度,得到的值单位pxpublic float getStatusBarHeight() {    float result = 0; int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = getResources().getDimension(resourceId); } return result;} 

//返回值就是导航栏的高度,得到的值单位pxpublic float getNavigationBarHeight() {    float result = 0; int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android"); if (resourceId > 0) { result = getResources().getDimension(resourceId); } return result;} 

Use of the Android:fitssystemwindows property

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.