這款第三方插件在github上相當有名,尤其是支持androidx之後,1.8版本之後整體都很穩定,能滿足開發需求,但是因爲自帶的幾個彈框都很醜,很長時間以來用的都是自定義,感覺比較繁瑣而且沒有必要,最近有時間拆解看看如何複用本來就提供的那些pop
-
庫組件修改
1)Loading:LoadingPopupView getImplLayoutId
使用layout爲R.layout._xpopup_center_impl_loading
框架是LinearLayout內部包含一個com.lxj.xpopup.widget.LoadingView和id爲tv_title的TextView
其中LoadingView是一個不能修改顏色"#CCCCCC-#333333",尺寸自適應的組件
2)Confirm確認:ConfirmPopupView getImplLayoutId
使用layout爲R.layout._xpopup_center_impl_confirm
框架是內部包含LinearLayout內部包含兩個textView,一個EditView兩個button
tv_title和tv_content顯示文字,et_input輸入和執行操作,tv_cancel和tv_confirm執行
3)單輸入框帶確認取消:InputConfirmPopupView
使用layout與ConfirmPopupView相同,繼承自ConfirmPopupView
4)顯示在中間的列表Popup:CenterListPopupView
使用layout爲_xpopup_center_impl_list,其內部控件爲LinearLayout,包含一個TextView的title,和VerticalRecyclerView的recyclerView,缺點是使用的adapter爲EasyAdapter,類型限定爲String[]比較死板,因此含有列表類的我都推薦自定義
5)寬高盛滿全屏:FullScreenPopupView
沒有任何內容,因此沒有layout,只是起到撐開的作用
6)顯示在底部的列表Popup:BottomListPopupView getImplLayoutId
使用layout爲_xpopup_center_impl_list,同CenterListPopupView。
7)依附於某View的列表彈窗:AttachListPopupView getImplLayoutId
layout爲R.layout._xpopup_attach_impl_list,layout中只有一個根節點VerticalRecyclerView
,其繼承自RecyclerView,是列表顯示的核心控件
8)局部陰影的彈窗PartShadowPopupView getImplLayoutId
說明曰:類似於淘寶商品列表的下拉篩選彈窗,可放於任意位置,繼承使用需要實現getImplLayoutId -
原生庫說明:
1)居中Pop:CenterPopupView getPopupLayoutId
默認返回_xpopup_center_popup_view,根節點爲FrameLayout,使用時應用根節點最好爲LinearLayout
2)底部彈出:BottomPopupView
layout爲_xpopup_bottom_popup_view,根節點爲SmartDragLayout,使用時應用根節點最好爲LinearLayout
3)帶drawer的彈窗:DrawerPopupView
默認返回,根節點爲drawerLayout PopupDrawerLayout,就是drawer部分,內部包含節點爲drawerContentContainer FrameLayout,
4)依附於某View的列表:AttachPopupView
layout爲R.layout._xpopup_attach_popup_view,同PositionPopupView,layout中只有一個根節點PartShadowContainer
,contentView獲取的是整個View
5)水平方向依附View:HorizontalAttachPopupView
6)自由定位的彈窗(允許居中):PositionPopupView
layout爲R.layout._xpopup_attach_popup_view,同AttachPopupView,layout中只有一個根節點PartShadowContainer
,contentView獲取的是整個View
根據設置判斷是否居中,如果居中取屏幕寬度與當前窗體之差的一半,設置爲左上點;不居中則按照配置中的(x,y)定位與屏幕
7)大圖瀏覽:ImageViewerPopupView
使用layout爲_xpopup_image_viewer_popup_view,其中包括兩個自定義組件:用於大圖瀏覽彈窗顯示後的有邊白色佔位View BlankView和核心部件ViewPager用於幻燈片播放的PhotoViewContainer,底部顯示有text用於顯示圖片頁碼和保存button -
XPopup配置修改
1)背景色修改:shadowBgColor,default:#9F000000
2)狀態欄背景色修改:statusBarShadowColor,default:#55000000
3)主色調修改:primaryColor,default:#121212
4)動畫持續時間:animationDuration,default:360
注意設置的顏色接受爲:Color的int值包括:
注意:PopupInfo中有全部可配置的選項的詳細說明,setBackground允許修改的背景色都是面板的而非半透明背景的。如設置該背景爲顏色,在第一次彈出時會有充滿全屏的效果一閃而過,猶如bug需要注意