问题修复
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.res.Resources
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
import androidx.appcompat.app.ActionBar
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.appcompat.widget.Toolbar
|
||||
@@ -21,6 +22,7 @@ import com.btpj.lib_base.base.BaseViewModel.Companion.LOADING_STATE_SHOW
|
||||
import com.btpj.lib_base.event.LoginEvent
|
||||
import com.btpj.lib_base.ext.hideLoading
|
||||
import com.btpj.lib_base.ext.showLoading
|
||||
import com.btpj.lib_base.utils.CustomToast
|
||||
import com.btpj.lib_base.utils.LogUtil
|
||||
import com.btpj.lib_base.utils.StatusBarUtil
|
||||
import com.btpj.lib_base.utils.ToastUtil
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package com.btpj.lib_base.utils;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.btpj.lib_base.R;
|
||||
|
||||
|
||||
/**
|
||||
* 自定义弹出对话框
|
||||
*
|
||||
* @author wyy
|
||||
*/
|
||||
public class CustomToast extends Toast {
|
||||
|
||||
private TextView textView;
|
||||
private static String mText = "";
|
||||
private View view;
|
||||
private int time;
|
||||
private Context context;
|
||||
private Drawable drawable;
|
||||
private static CustomToast result;
|
||||
|
||||
public CustomToast(Context context, String text, int time) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.mText = text;
|
||||
this.time = time;
|
||||
init();
|
||||
}
|
||||
|
||||
public CustomToast(Context context, String text, int time, Drawable drawable) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.mText = text;
|
||||
this.time = time;
|
||||
this.drawable=drawable;
|
||||
init();
|
||||
}
|
||||
public CustomToast(Context context, String text, int time, int gravity ) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
this.mText = text;
|
||||
this.time = time;
|
||||
init2(gravity);
|
||||
}
|
||||
|
||||
private void init() {
|
||||
try {
|
||||
view = View.inflate(context, R.layout.custom_toast, null);
|
||||
setView(view);
|
||||
textView = (TextView) view.findViewById(R.id.textView);
|
||||
textView.setText(mText);
|
||||
if (drawable!=null) {
|
||||
textView.setCompoundDrawables(null,drawable,null,null);
|
||||
}
|
||||
setGravity(Gravity.CENTER, 0, -100);
|
||||
setDuration(time);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
private void init2(int gravity) {
|
||||
try {
|
||||
view = View.inflate(context, R.layout.custom_toast, null);
|
||||
setView(view);
|
||||
textView = (TextView) view.findViewById(R.id.textView);
|
||||
textView.setText(mText);
|
||||
textView.setGravity(gravity);
|
||||
if (drawable!=null) {
|
||||
textView.setCompoundDrawables(null,drawable,null,null);
|
||||
}
|
||||
setGravity(Gravity.CENTER, 0, -100);
|
||||
setDuration(time);
|
||||
} catch (Exception e) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static CustomToast makeText(Context context, CharSequence text, int duration,int gravity) {
|
||||
if (result == null || !mText.equals(text) ) {
|
||||
result = new CustomToast(context, text.toString(), duration,gravity);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static CustomToast makeText(Context context, CharSequence text, int duration) {
|
||||
if (result == null || !mText.equals(text) ) {
|
||||
result = new CustomToast(context, text.toString(), duration);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static CustomToast makeText(Context context, CharSequence text, int duration, Drawable drawable) {
|
||||
if (result == null || !mText.equals(text) ) {
|
||||
result = new CustomToast(context, text.toString(), duration,drawable);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public static void reset(){
|
||||
result=null;
|
||||
}
|
||||
}
|
||||
@@ -23,7 +23,9 @@ object ToastUtil {
|
||||
if(msg.isNullOrEmpty()){
|
||||
return
|
||||
}
|
||||
Toast.makeText(context.applicationContext, msg, Toast.LENGTH_SHORT).show()
|
||||
// Toast.makeText(context.applicationContext, msg, Toast.LENGTH_SHORT).show()
|
||||
CustomToast.makeText(context,msg,Toast.LENGTH_SHORT).show()
|
||||
|
||||
}
|
||||
fun showShort(context: Context, @StringRes resId: Int) {
|
||||
Toast.makeText(context.applicationContext, resId, Toast.LENGTH_SHORT).show()
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_toast_shape"
|
||||
android:gravity="center"
|
||||
android:textSize="16dp"
|
||||
android:padding="16dp"
|
||||
android:textColor="@color/white" />
|
||||
|
||||
</LinearLayout>
|
||||
Reference in New Issue
Block a user