自定义 view toast
This commit is contained in:
parent
89ced0be17
commit
ceb91122b0
|
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
|
||||
<solid android:color="#66EEEEEE" />
|
||||
<corners android:radius="15dp" />
|
||||
<stroke
|
||||
android:width="0dp"
|
||||
android:color="#00000000" />
|
||||
|
||||
</shape>
|
||||
|
|
@ -12,14 +12,20 @@ import android.os.Handler
|
|||
import android.os.Looper
|
||||
import android.provider.Settings
|
||||
import android.view.Gravity
|
||||
import android.view.LayoutInflater
|
||||
import android.view.PixelCopy
|
||||
import android.view.View
|
||||
import android.view.Window
|
||||
import android.webkit.WebView
|
||||
import android.widget.ImageView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.widget.AppCompatImageView
|
||||
import androidx.appcompat.widget.AppCompatTextView
|
||||
import androidx.core.app.NotificationManagerCompat
|
||||
import androidx.core.graphics.createBitmap
|
||||
import com.ama.core.architecture.BaseApp
|
||||
import com.ama.core.architecture.R
|
||||
import com.ama.core.architecture.databinding.LayoutToastCenterBinding
|
||||
import com.google.android.gms.ads.identifier.AdvertisingIdClient
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
|
|
@ -32,6 +38,7 @@ class AndroidUtil private constructor() {
|
|||
companion object {
|
||||
val gson: Gson = Gson()
|
||||
|
||||
|
||||
fun genRandomInt(rangeBegin: Int, rangeEnd: Int): Int {
|
||||
return Random.nextInt(rangeBegin, rangeEnd)
|
||||
}
|
||||
|
|
@ -75,6 +82,19 @@ class AndroidUtil private constructor() {
|
|||
}
|
||||
}
|
||||
|
||||
fun showCustomToast(textStr: String, iconRes: Int) {
|
||||
val layout: View = LayoutInflater.from(BaseApp.appContext()).inflate(R.layout.layout_toast_center, null)
|
||||
layout.findViewById<AppCompatImageView>(R.id.iv_top).setImageResource(iconRes)
|
||||
layout.findViewById<AppCompatTextView>(R.id.tv_bottom).text = textStr
|
||||
|
||||
Toast(BaseApp.appContext()).apply {
|
||||
duration = Toast.LENGTH_SHORT
|
||||
setGravity(Gravity.CENTER or Gravity.CENTER_HORIZONTAL, 0, 10)
|
||||
setView(layout)
|
||||
show()
|
||||
}
|
||||
}
|
||||
|
||||
fun openUrl(url: String) {
|
||||
val appContext = BaseApp.appContext()
|
||||
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="150dp"
|
||||
android:background="@drawable/bg_custom_toast"
|
||||
tools:ignore="ResourceName">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center_horizontal"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/iv_top"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@mipmap/home_gold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tv_bottom"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="10dp"
|
||||
android:text="hint"
|
||||
android:textSize="15sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
Loading…
Reference in New Issue