-
Notifications
You must be signed in to change notification settings - Fork 4
Popup with blur background
Prem Ankur edited this page Dec 27, 2018
·
1 revision
- To create a popup with blur background:
- Create a dialogFragment class with BaseBlurPopup() as superclass and override the following methods
class SampleBlurPopup : BaseBlurPopup() { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? = inflater.inflate(R.layout.popup_sample_blur, container, false) /** * Optional - override for customizing enter animation of the root view returned by [getRootView()] */ override fun enterAnimation(): Int = enterAnim /** * Optional - override for customizing exit animation of the root view returned by [getRootView()] */ override fun dismissAnimation(): Int = exitAnim /** * Return the background layout (preferably BlurLayout) for effects during transition, return null for transparent background and no effects */ override fun getBlurLayout(): BlurLayout? = blurLayout /** * Return the Drag area that should be used for swipe gestures, return null for no drag gesture implementations */ override fun getDragHandle(): View? = dragArea /** * Return the root view (preferably a CardView) of the fragment */ override fun getRootView(): View? = rootCard /** * Return the background layout (preferably BlurLayout) for effects during transition, return null for transparent background and no effects */ override fun getBackgroundLayout(): ViewGroup? = blurLayout }- Add XML data to fragment's layout (refer to styles.xml for style templates):
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" style="@style/MatchParentMatchParent"> <io.alterac.blurkit.BlurLayout android:id="@+id/blurLayout" style="@style/BlurLayoutFullScreen" /> <androidx.cardview.widget.CardView android:id="@+id/rootCard" style="@style/CardView.WrapHeight" android:layout_gravity="center"> <ScrollView style="@style/MatchParentMatchParent"> <RelativeLayout style="@style/MatchParentMatchParent" android:orientation="vertical"> <ImageView android:id="@+id/popupThumbnail" android:layout_width="match_parent" android:layout_height="wrap_content" android:contentDescription="@string/thumbnail" android:minHeight="100dp" android:scaleType="centerCrop" /> <TextView android:id="@+id/popupHeader" style="@style/MatchParentWrapContent" android:layout_below="@+id/popupThumbnail" android:layout_gravity="center_horizontal" android:gravity="center" android:padding="20dp" android:text="@string/this_is_a_sample_blur_popup" android:textColor="@color/grey" android:textSize="16sp" android:textStyle="bold" /> <TextView android:id="@+id/popupInfo" style="@style/MatchParentWrapContent" android:layout_below="@+id/popupHeader" android:layout_gravity="center_horizontal" android:gravity="center" android:paddingStart="20dp" android:paddingTop="10dp" android:paddingEnd="20dp" android:paddingBottom="10dp" android:text="@string/blur_popup_implementation" android:textColor="@color/grey_0_7" android:textSize="14sp" /> </RelativeLayout> </ScrollView> <ImageView android:id="@+id/drag_handle_image" style="@style/DragHandleLight" android:contentDescription="@string/drag_handle" /> <View android:id="@+id/dragArea" style="@style/DragAreaWrap" /> </androidx.cardview.widget.CardView> </FrameLayout>