parent
a6a7b80b73
commit
9c88f40291
@ -0,0 +1,29 @@
|
|||||||
|
package com.common.bluetooth.utils
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.widget.TextView
|
||||||
|
import android.widget.Toast
|
||||||
|
import com.common.bluetooth.R
|
||||||
|
|
||||||
|
/**
|
||||||
|
* toast工具类
|
||||||
|
*/
|
||||||
|
class ToastUtil {
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
/**
|
||||||
|
* 展示自定义背景和信息的toast
|
||||||
|
*/
|
||||||
|
fun showCustomToast(context: Context, msg: String) {
|
||||||
|
val view = LayoutInflater.from(context).inflate(R.layout.my_toast_layout, null, false)
|
||||||
|
val textView = view.findViewById<TextView>(R.id.tv_toast_msg)
|
||||||
|
textView.text = msg
|
||||||
|
var toast: Toast = Toast(context)
|
||||||
|
toast.duration = Toast.LENGTH_SHORT
|
||||||
|
toast.view = view
|
||||||
|
toast.show()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
<solid android:color="@color/color_E6565D65" />
|
||||||
|
<corners android:radius="4dp" />
|
||||||
|
<padding
|
||||||
|
android:bottom="15dp"
|
||||||
|
android:left="52dp"
|
||||||
|
android:right="52dp"
|
||||||
|
android:top="15dp" />
|
||||||
|
|
||||||
|
</shape>
|
@ -0,0 +1,19 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tv_toast_msg"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:background="@drawable/custom_toast_layout"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="18dp"
|
||||||
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
app:layout_constraintLeft_toLeftOf="parent"
|
||||||
|
app:layout_constraintRight_toRightOf="parent"
|
||||||
|
app:layout_constraintTop_toTopOf="parent" />
|
||||||
|
|
||||||
|
</androidx.constraintlayout.widget.ConstraintLayout>
|
Loading…
Reference in New Issue