[charter]
[3.2.0] [自定义吐司]
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
package com.mogo.och.bus.passenger.utils
|
||||
|
||||
import android.view.View
|
||||
import com.mogo.eagle.core.utilcode.util.ActivityUtils
|
||||
import com.mogo.eagle.core.utilcode.util.ToastUtils
|
||||
import com.mogo.och.bus.passenger.view.ToastCharterView
|
||||
import me.jessyan.autosize.utils.AutoSizeUtils
|
||||
|
||||
object ToastCharterUtils {
|
||||
fun showTaost(toastText:String){
|
||||
val context = ActivityUtils.getTopActivity()
|
||||
val marker = ToastCharterView(context)
|
||||
marker.setText(toastText)
|
||||
marker.measure(
|
||||
View.MeasureSpec.makeMeasureSpec(AutoSizeUtils.dp2px(context, 145f), View.MeasureSpec.UNSPECIFIED),
|
||||
View.MeasureSpec.makeMeasureSpec(AutoSizeUtils.dp2px(context, 34f), View.MeasureSpec.EXACTLY)
|
||||
)
|
||||
marker.layout(0, 0, marker.measuredWidth, marker.measuredHeight)
|
||||
ToastUtils.showShort(marker)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package com.mogo.och.bus.passenger.view
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import com.mogo.och.bus.passenger.R
|
||||
import kotlinx.android.synthetic.main.charter_p_view_toast.view.*
|
||||
|
||||
class ToastCharterView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : ConstraintLayout (
|
||||
context,
|
||||
attrs,
|
||||
defStyleAttr
|
||||
) {
|
||||
|
||||
init {
|
||||
LayoutInflater.from(context).inflate(R.layout.charter_p_view_toast, this, true)
|
||||
}
|
||||
|
||||
fun setText(siteName: String) {
|
||||
tv_taost_texit.text = siteName
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
|
||||
<solid android:color="@color/bus_p_m1_B3EFF6FF"/>
|
||||
<corners android:radius="@dimen/dp_26"/>
|
||||
</shape>
|
||||
@@ -0,0 +1,25 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<LinearLayout
|
||||
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="wrap_content"
|
||||
android:layout_height="wrap_content">
|
||||
<androidx.appcompat.widget.AppCompatTextView
|
||||
android:id="@+id/tv_taost_texit"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/charter_p_toast_shape"
|
||||
android:button="@null"
|
||||
android:gravity="center"
|
||||
android:paddingStart="@dimen/dp_62"
|
||||
android:paddingTop="@dimen/dp_32"
|
||||
android:paddingEnd="@dimen/dp_62"
|
||||
android:paddingBottom="@dimen/dp_32"
|
||||
android:textColor="@color/bus_p_m1_112b57"
|
||||
android:textSize="34dp"
|
||||
android:layout_marginBottom="@dimen/dp_50"
|
||||
tools:text="18" />
|
||||
</LinearLayout>
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
<color name="bus_p_m1_3060ABFE">#3060ABFE</color>
|
||||
<color name="bus_p_m1_0060ABFE">#0060ABFE</color>
|
||||
<color name="bus_p_m1_00EFF6FF">#00EFF6FF</color>
|
||||
<color name="bus_p_m1_B3EFF6FF">#B3EFF6FF</color>
|
||||
<color name="bus_p_m1_91EFF6FF">#91EFF6FF</color>
|
||||
<color name="bus_p_m1_CCFFFFFF">#CCFFFFFF</color>
|
||||
<color name="bus_p_m1_80ffffff">#80FFFFFF</color>
|
||||
|
||||
@@ -453,6 +453,26 @@ public final class ToastUtils {
|
||||
show(UtilsBridge.format(format, args), Toast.LENGTH_LONG, DEFAULT_MAKER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the toast for a short period of time.
|
||||
*
|
||||
*/
|
||||
public static void showShort(@Nullable final View view) {
|
||||
if(view!=null){
|
||||
show(view, Toast.LENGTH_SHORT, DEFAULT_MAKER);
|
||||
}else {
|
||||
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Show the toast for a short period of time.
|
||||
*
|
||||
*/
|
||||
public static void showLong(@Nullable final View view) {
|
||||
show(view, Toast.LENGTH_LONG, DEFAULT_MAKER);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Cancel the toast.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user