1. 修改TipToast背景为渐变

2. 增加左侧带图片的TipToast
This commit is contained in:
tongchenfei
2020-09-01 16:46:59 +08:00
parent 5673ec457f
commit 6e6c305230
12 changed files with 274 additions and 61 deletions

View File

@@ -4,6 +4,8 @@ import android.app.Application;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.alibaba.android.arouter.launcher.ARouter;
@@ -17,6 +19,7 @@ import com.mogo.commons.network.ParamsUtil;
import com.mogo.commons.network.X509TrustManagerImpl;
import com.mogo.commons.storage.SpStorage;
import com.mogo.utils.ThreadPoolService;
import com.mogo.utils.TipDrawable;
import com.mogo.utils.TipToast;
import com.mogo.utils.network.NetConfig;
@@ -65,13 +68,26 @@ public class AbsMogoApplication extends Application {
ARouter.openLog();
}
ARouter.init( sApp );
TipToast.init( this, ( ( context, message ) -> {
TipToast.init( this, ( ( context, message, tipDrawable ) -> {
if ( TextUtils.isEmpty( message ) ) {
return null;
}
View contentView = LayoutInflater.from( context ).inflate( R.layout.module_commons_layout_toast, null );
TextView txt = contentView.findViewById( R.id.module_commons_toast_msg );
txt.setText( message );
View contentView;
if(tipDrawable==null) {
contentView = LayoutInflater.from(context).inflate(R.layout.module_commons_layout_toast, null);
TextView txt = contentView.findViewById(R.id.module_commons_toast_msg);
txt.setText(message);
}else{
// 有图片,使用带图片的布局,当前只实现了左侧图片
contentView = LayoutInflater.from(context).inflate(R.layout.module_commons_layout_toast_with_left_drawable, null);
TextView txt = contentView.findViewById(R.id.module_commons_toast_msg);
ImageView img = contentView.findViewById(R.id.module_commons_toast_left_drawable);
img.setImageDrawable(tipDrawable.getDrawable());
ViewGroup.LayoutParams params = img.getLayoutParams();
params.width = tipDrawable.getWidth();
params.height = tipDrawable.getHeight();
txt.setText(message);
}
return contentView;
} ) );
}