Android劉海屏適配庫NotchFit簡介及使用方式

NotchFit

智能劉海屏適配庫

優點:使用簡單,劉海蔘數智能判斷,一鍵式劉海蔘數回調,無需考慮機型差異,適配O版本和P版本。

劉海屏存在於系統O版本、P版本及以上版本,由於google P版本劉海api推出較晚,導致O版本劉海屏的不同廠商的機型有各自不同的
適配方式,再者不同手機系統劉海區域使用設置也有所不同,有的默認開啓,有的默認關閉,導致劉海屏適配比較繁瑣和複雜,此庫
處理了以上所有的問題,並智能判斷劉海區域的使用方式和劉海蔘數的獲取,給開發者更好的劉海適配體驗!

引入方式

compile 'com.wcl.notchfit:notchfit:1.3'

使用方式

1.沉浸適配

name

  NotchFit.fit(this, NotchScreenType.TRANSLUCENT, new OnNotchCallBack() {
        @Override
        public void onNotchReady(NotchProperty notchProperty) {
            if(notchProperty.isNotchEnable()){
                ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) listParent.getLayoutParams();
                marginLayoutParams.topMargin = notchProperty.getNotchHeight();
                listParent.requestLayout();
            }
        }
   });

2.全屏適配

name

  NotchFit.fit(this, NotchScreenType.FULL_SCREEN, new OnNotchCallBack() {
              @Override
              public void onNotchReady(NotchProperty notchProperty) {
                  if(notchProperty.isNotchEnable()){
                      ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) listParent.getLayoutParams();
                      marginLayoutParams.topMargin = notchProperty.getNotchHeight();
                      listParent.requestLayout();
                  }
              }
          });

3.黑條填充

name

 NotchFit.fitUnUse(this);

更多使用方式請查看github NotchFit

此庫若有bug,歡迎指出,多謝多謝!!!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章