劉海屏適配NotchF
阿新 • • 發佈:2018-12-19
NotchFit
智慧劉海屏適配庫 優點:使用簡單,智慧劉海判斷,一鍵式劉海蔘數回撥,無需考慮機型差異,適配O版本和P版本。
劉海屏存在於系統O版本、P版本及以上版本,由於google P版本劉海api推出較晚,導致O版本劉海屏的不同廠商的機型有各自不同的
適配方式,再者不同手機系統劉海區域使用設定也有所不同,有的預設開啟,有的預設關閉,導致劉海屏適配比較繁瑣和複雜,此庫
處理了以上所有的問題,並智慧判斷劉海區域的使用方式和劉海蔘數的獲取,給開發者更好的劉海適配體驗!
引入方式
compile 'com.wcl.notchfit:notchfit:1.0'
使用方式
1.沉浸適配
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.全屏適配
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.黑條填充
NotchFit.fitUnUse(this);
更多使用方式請檢視[github NotchFit](https://github.com/wcl9900/NotchFit)