desc:应用内自己实现恢复出厂设置功能
							parent
							
								
									a5d55cd849
								
							
						
					
					
						commit
						32532c035e
					
				| @ -0,0 +1,55 @@ | |||||||
|  | package com.yinuo.safetywatcher.watcher.ui.view | ||||||
|  | 
 | ||||||
|  | import android.graphics.Color | ||||||
|  | import android.graphics.drawable.ColorDrawable | ||||||
|  | import android.os.Bundle | ||||||
|  | import android.view.Gravity | ||||||
|  | import android.view.LayoutInflater | ||||||
|  | import android.view.View | ||||||
|  | import android.view.ViewGroup | ||||||
|  | import androidx.fragment.app.DialogFragment | ||||||
|  | import com.yinuo.safetywatcher.R | ||||||
|  | import com.yinuo.safetywatcher.databinding.LayoutConfirmDialogBinding | ||||||
|  | 
 | ||||||
|  | class ConfirmDialog( | ||||||
|  |     private val tipResID: Int = R.string.confirm_clear_data_tip, | ||||||
|  |     private val onConfirmClick: (() -> Unit?)? = null | ||||||
|  | ) : | ||||||
|  |     DialogFragment() { | ||||||
|  | 
 | ||||||
|  |     var dialogBinding: LayoutConfirmDialogBinding? = null | ||||||
|  | 
 | ||||||
|  |     override fun onCreateView( | ||||||
|  |         inflater: LayoutInflater, | ||||||
|  |         container: ViewGroup?, | ||||||
|  |         savedInstanceState: Bundle? | ||||||
|  |     ): View? { | ||||||
|  |         dialogBinding = LayoutConfirmDialogBinding.inflate(inflater, container, false) | ||||||
|  |         dialogBinding!!.tip.text = getString(tipResID) | ||||||
|  |         dialogBinding!!.tvConfirm.setOnClickListener { | ||||||
|  |             onConfirmClick?.invoke() | ||||||
|  |         } | ||||||
|  |         dialogBinding!!.tvCancel.setOnClickListener { | ||||||
|  |             this@ConfirmDialog.dismiss() | ||||||
|  |         } | ||||||
|  |         return dialogBinding!!.root | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     @Deprecated("Deprecated in Java") | ||||||
|  |     override fun onActivityCreated(savedInstanceState: Bundle?) { | ||||||
|  |         super.onActivityCreated(savedInstanceState) | ||||||
|  |         initWindow() | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     private fun initWindow() { | ||||||
|  |         //初始化window相关表现 | ||||||
|  |         val window = dialog?.window | ||||||
|  |         //设备背景为透明(默认白色) | ||||||
|  |         window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT)) | ||||||
|  |         //设置window宽高(单位px) | ||||||
|  |         window?.attributes?.width = 480 | ||||||
|  |         window?.attributes?.height = 320 | ||||||
|  |         //设置window位置 | ||||||
|  |         window?.attributes?.gravity = Gravity.CENTER//居中 | ||||||
|  |     } | ||||||
|  | } | ||||||
| @ -0,0 +1,49 @@ | |||||||
|  | <?xml version="1.0" encoding="utf-8"?> | ||||||
|  | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||||||
|  |     android:layout_width="@dimen/_480dp" | ||||||
|  |     android:layout_height="@dimen/_320dp" | ||||||
|  |     android:background="@drawable/warn_setting_btn_bg" | ||||||
|  |     android:orientation="vertical"> | ||||||
|  | 
 | ||||||
|  |     <TextView | ||||||
|  |         android:id="@+id/tip" | ||||||
|  |         android:layout_width="wrap_content" | ||||||
|  |         android:layout_height="0dp" | ||||||
|  |         android:layout_gravity="center" | ||||||
|  |         android:layout_marginTop="@dimen/_36dp" | ||||||
|  |         android:layout_weight="1" | ||||||
|  |         android:gravity="center" | ||||||
|  |         android:text="@string/sync_data_tip" | ||||||
|  |         android:textColor="@color/white" | ||||||
|  |         android:textSize="@dimen/_30dp" /> | ||||||
|  | 
 | ||||||
|  |     <LinearLayout | ||||||
|  |         android:layout_width="match_parent" | ||||||
|  |         android:layout_height="wrap_content"> | ||||||
|  | 
 | ||||||
|  |         <TextView | ||||||
|  |             android:id="@+id/tv_cancel" | ||||||
|  |             android:layout_width="0dp" | ||||||
|  |             android:layout_height="@dimen/_81dp" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:background="@drawable/cancel_btn_bg" | ||||||
|  |             android:focusable="true" | ||||||
|  |             android:gravity="center" | ||||||
|  |             android:focusedByDefault="true" | ||||||
|  |             android:text="@string/cancel" | ||||||
|  |             android:textColor="@color/white_30" | ||||||
|  |             android:textSize="@dimen/_36dp" /> | ||||||
|  | 
 | ||||||
|  |         <TextView | ||||||
|  |             android:id="@+id/tv_confirm" | ||||||
|  |             android:layout_width="0dp" | ||||||
|  |             android:layout_height="@dimen/_81dp" | ||||||
|  |             android:layout_weight="1" | ||||||
|  |             android:background="@drawable/confirm_btn_bg" | ||||||
|  |             android:focusable="true" | ||||||
|  |             android:gravity="center" | ||||||
|  |             android:text="@string/confirm" | ||||||
|  |             android:textColor="@color/white" | ||||||
|  |             android:textSize="@dimen/_36dp" /> | ||||||
|  |     </LinearLayout> | ||||||
|  | </LinearLayout> | ||||||
					Loading…
					
					
				
		Reference in New Issue