Android bangs screen adaptation ----- ImmersionBar

android 4.4 and above immersive status bar immersive navigation management, adaptation had to switch screens, bangs screen, the soft keyboard pops up and other issues, you can modify the status bar font color and navigation bar icon color, font color and can not be modified phone adapter for Activity, Fragment, DialogFragment, Dialog, PopupWindow;

  1. Introduced

    // foundation dependencies, must rely Implementation 'com.gyf.immersionbar: immersionbar: 3.0.0' // the fragment quickly implement (optional) Implementation 'com.gyf.immersionbar: immersionbar-Components: 3.0.0' // kotlin extension (optional) implementation 'com.gyf.immersionbar: immersionbar-ktx : 3.0.0
  2. Comprehensive screen with bangs

    Application node ① is added at the manifest

     <meta-data 
         android:name="android.max_aspect"
         android:value="2.4" />

     

    ② added to the Application node manifest in

    android:resizeableActivity="true"

     

    Application node ③ is added in the manifest

     android:maxAspectRatio="2.4"

     

    ④ upgrade targetSdkVersion 25 or later

  3. About bangs screen

    In the Application node join the manifest, vivo and oppo No configuration information found

       <! - adapted Huawei (HUAWEI) bangs screen -> 
       <meta- Data 
         Android: name = "android.notch_support"  
         Android: value = "to true" /> 
       ! <- adapted millet (Xiaomi) bangs screen - -> 
       <meta- Data 
         Android: name = "notch.config" 
         Android: value = "Portrait | Landscape" />

    usage

    initialization

    • Basic usage (already meet the daily immersion)

      ImmersionBar.with(this).init();
    • Advanced usage (meaning each parameter)

      ImmersionBar.with ( the this ) 
                   .transparentStatusBar ()   // transparent status bar, do not write the default transparent color 
                   .transparentNavigationBar ()   // transparent navigation bar, do not write the default black (set this method, fullScreen () method automatically to true) 
                   .transparentBar ()              // transparent status and navigation bars, do not write the status bar by default transparent color, black navigation bar (set this method, fullScreen () method automatically to true) 
                   .statusBarColor (R.color.colorPrimary)      // status bar color, do not write the default transparent color 
                   .navigationBarColor (R.color.colorPrimary) // navigation bar color, do not write the default black 
                   .barColor (R.color.colorPrimary)   // while custom status bar and the navigation bar color, do not write default The status bar is transparent, the navigation bar is black 
                   .statusBarAlpha (0.3f)   // status bar transparency, do not write the default 0.0f
                   .navigationBarAlpha (0.4F)   // navigation bar transparency, do not write the default 0.0F 
                   .barAlpha (0.3f)   // status and navigation bars transparency, do not write the default 0.0f 
                   .statusBarDarkFont ( to true )    // The status bar is dark font , do not write the default is bright 
                   .navigationBarDarkIcon ( to true ) // navigation bar icon is dark, do not write the default is bright 
                   .autoDarkModeEnable ( to true ) // auto navigation bar and status bar icon font color, you must specify the color of the status bar and navigation bar color can automatically change color oh 
                   .autoStatusBarDarkModeEnable ( to true , 0.2f) // automatic status bar font color, you must specify the status bar color can automatically change color oh 
                   .autoNavigationBarDarkModeEnable ( to true , 0.2f) //Automatic navigation bar icon color, you must specify the navigation bar color can automatically change color oh 
                   .flymeOSStatusBarFontColor (R.color.btn3)   // modify flyme OS status bar font color 
                   .fullScreen ( to true )       // under the navigation bar of the situation, activity fullscreen show, that activity is covered by the bottom navigation bar, do not write non-default full-screen 
                   .hideBar (BarHide.FLAG_HIDE_BAR)   // hide the status bar or navigation bars, or both, do not write the default is not hidden 
                   .addViewSupportTransformColor (toolbar)   // set support color view may be added a plurality of view, no color is specified, the default status bar, and the same color, there are two overloaded methods 
                   .titleBar (view)     // resolve overlap layout status bar and, optionally one 
                   .titleBarMarginTop (view)      // resolve the status bar and layout overlap issues, choose one 
                   .statusBarView (View)   // solve the problem of overlapping status bar and layout, choose one
                   .fitsSystemWindows ( to true )     // solve the problem of overlapping status bar and layout, choose one, the default is false, be sure to specify when statusBarColor is true (), otherwise the status bar is transparent, there are overloaded methods 
                   .supportActionBar ( to true ) // support ActionBar use 
                   .statusBarColorTransform (R.color.orange)   // after the status bar color color 
                   .navigationBarColorTransform (R.color.orange) // color of the navigation bar discoloration 
                   .barColorTransform (R.color.orange )   // status bar and the navigation bar color color 
                   .removeSupportView (toolbar)   // Removes the specified view support 
                   .removeSupportAllView () // remove all view support 
                   .navigationBarEnable (to true )    // whether you can modify the color of the navigation bar, defaults to true 
                   .navigationBarWithKitkatEnable ( to true )   // Can I modify Android 4.4 and emui3.1 mobile navigation bar color, default to true 
                   .fixMarginAtBottom ( to true )    // obsolete, when xml in use android: when fitsSystemWindows = "true" attribute to address the 4.4 emui3.1 bottom of the phone and sometimes extra white space problems occur, the default is false, non-essential 
                   .addTag ( "tag")   // to set the parameters above marking 
                   .getTag ( "tag")   // according tag parameters obtained immersive 
                   .reset ()   // reset so immersive parameters 
                   .keyboardEnable ( to true )   // solve the soft keyboard input box with the bottom of the conflict, the default is false, there an overloaded method, you can specify soft keyboard mode
                   .keyboardMode (WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE)   // specify a separate soft keyboard mode 
                   .setOnKeyboardListener ( new new OnKeyboardListener () {     // soft keyboard callback listener 
                         @Override
                          public  void onKeyboardChange ( Boolean isPopUp, int keyboardHeight) { 
                             LogUtils.e (isPopUp);   // isPopUp true, the soft keyboard pops up, is false, the soft keyboard close 
                         } 
                    }) 
                   .init ();   // must be called before immersion

      Close destroyed

      • OnDestroy activity performed in the method

        ImmersionBar.with ( the this ) .destroy (); // must call this method to prevent memory leaks

      Suggest

      • We recommend initialization and destruction in the BaseActivity

        public  class BaseActivity the extends AppCompatActivity { 
        
             @Override 
             protected  void the onCreate (@Nullable the Bundle savedInstanceState) {
                  Super .onCreate (savedInstanceState);
                  // All subclasses inherit these same attributes, after setting the interface 
                 ImmersionBar.with ( the this ) .init ();   
             } 
           
             @Override 
             protected  void onResume () {
                  Super .onResume ();
                  // non-essential plus
                  // If your app can switch the screen anyway, adaptation Huawei emui3 series phone system, and navigationBarWithEMUI3Enable is true,
                  //Please add this code in onResume method in (at the same time meet the three conditions only need to add the code Oh: 1, horizontal and vertical screen can switch; 2, Huawei emui3 series phone system; 3, navigationBarWithEMUI3Enable as to true)
                  // otherwise ignored 
                 if (OSUtils.isEMUI3_x ()) { 
                     ImmersionBar.with ( the this ) .init ();    
                 }    
             } 
         
             @Override 
             protected  void onDestroy () {
                  Super .onDestroy ();
                  // must call this method to prevent a memory leak 
                 ImmersionBar.with ( the this ) .destroy ();   
             } 
           
            @Override 
             protected  void onConfigurationChanged (the Configuration newConfig) {
                  Super.onConfigurationChanged (newConfig);
                  // non-essential plus
                  // If your app can switch the screen anyway, adaptation or 4.4 Huawei emui3.1 phone system, and navigationBarWithKitkatEnable as to true,
                  // make sure to add the following code in the method onConfigurationChanged (At the same time meet the three conditions only need to add the code Oh: 1, horizontal and vertical screen can switch; 2, android4.4 Huawei emui3.1 system or mobile phone; 3, navigationBarWithKitkatEnable as to true)
                  // otherwise ignore 
                 ImmersionBar.with ( the this ) .init ();    
             } 
         }

         

        Demo Download: https://github.com/gyf-dev/ImmersionBar

         

        By: Yang

         

 

Guess you like

Origin www.cnblogs.com/widgetbox/p/11959436.html