desc:自定义dialog和弹框
parent
08064c5a85
commit
f1ea0f998d
@ -0,0 +1,32 @@
|
|||||||
|
package com.yinuo.safetywatcher.watcher.ui.view
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.Gravity
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.widget.Toast
|
||||||
|
import com.yinuo.safetywatcher.databinding.LayoutCommonToastBinding
|
||||||
|
|
||||||
|
open class CommonToast(context: Context?) : Toast(context) {
|
||||||
|
|
||||||
|
var mBinding: LayoutCommonToastBinding? = null
|
||||||
|
|
||||||
|
init {
|
||||||
|
mBinding = LayoutCommonToastBinding.inflate(LayoutInflater.from(context), null, false)
|
||||||
|
view = mBinding!!.root
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun setText(text: CharSequence) {
|
||||||
|
mBinding!!.tv.text = text
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun makeCommonText(
|
||||||
|
context: Context,
|
||||||
|
text: CharSequence, duration: Int
|
||||||
|
): Toast {
|
||||||
|
val result = CommonToast(context)
|
||||||
|
result.setText(text)
|
||||||
|
result.setGravity(Gravity.CENTER, 0, 0)
|
||||||
|
result.duration = duration
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
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.databinding.LayoutSyncDialogBinding
|
||||||
|
|
||||||
|
class SyncDialog : DialogFragment() {
|
||||||
|
|
||||||
|
override fun onCreateView(
|
||||||
|
inflater: LayoutInflater,
|
||||||
|
container: ViewGroup?,
|
||||||
|
savedInstanceState: Bundle?
|
||||||
|
): View? {
|
||||||
|
val dialogBinding = LayoutSyncDialogBinding.inflate(inflater, container, false)
|
||||||
|
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 = 320
|
||||||
|
window?.attributes?.height = 320
|
||||||
|
//设置window位置
|
||||||
|
window?.attributes?.gravity = Gravity.CENTER//居中
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/warn_setting_btn_bg"
|
||||||
|
android:padding="@dimen/_50dp"
|
||||||
|
android:maxWidth="@dimen/_600dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="@dimen/_40dp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="@dimen/_320dp"
|
||||||
|
android:layout_height="@dimen/_320dp"
|
||||||
|
android:background="@drawable/warn_setting_btn_bg"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="@dimen/_132dp"
|
||||||
|
android:layout_height="@dimen/_132dp"
|
||||||
|
android:src="@mipmap/ic_sync" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="@dimen/_36dp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="@dimen/_30dp"
|
||||||
|
android:text="@string/sync_data_tip"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
Binary file not shown.
After Width: | Height: | Size: 9.3 KiB |
Loading…
Reference in New Issue