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;
} ) );
}

View File

@@ -2,7 +2,7 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<corners android:radius="90dp" />
<gradient
android:angle="270"
android:endColor="#F2161616"
android:startColor="#F2161616" />
android:angle="180"
android:endColor="#FF3F4057"
android:startColor="#FF5E6079" />
</shape>

View File

@@ -1,27 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/module_commons_toast_bkg"
android:orientation="vertical">
android:paddingTop="@dimen/module_commons_toast_marginTop"
android:paddingBottom="@dimen/module_commons_toast_marginBottom"
android:paddingLeft="@dimen/module_commons_toast_marginLeft"
android:paddingRight="@dimen/module_commons_toast_marginRight">
<TextView
android:id="@+id/module_commons_toast_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/module_commons_toast_marginLeft"
android:layout_marginTop="@dimen/module_commons_toast_marginTop"
android:layout_marginRight="@dimen/module_commons_toast_marginRight"
android:layout_marginBottom="@dimen/module_commons_toast_marginBottom"
android:ellipsize="end"
android:gravity="center"
android:drawablePadding="@dimen/module_commons_toast_space_between_icon_and_msg"
android:maxWidth="@dimen/module_commons_toast_maxWidth"
android:maxLength="20"
android:maxLines="1"
android:minWidth="@dimen/module_commons_toast_minWidth"
android:textColor="#FFFF"
android:textSize="@dimen/module_commons_toast_textSize"
tools:text="测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试测试" />
</LinearLayout>
tools:text="测试测试测试" />
<!-- android:minWidth="@dimen/module_commons_toast_minWidth"-->
</FrameLayout>

View File

@@ -0,0 +1,39 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/module_commons_toast_bkg"
android:orientation="horizontal"
android:paddingLeft="@dimen/module_commons_toast_with_left_drawable_marginLeft"
android:paddingTop="@dimen/module_commons_toast_with_left_drawable_marginTop"
android:paddingRight="@dimen/module_commons_toast_marginRight"
android:paddingBottom="@dimen/module_commons_toast_with_left_drawable_marginBottom">
<ImageView
android:id="@+id/module_commons_toast_left_drawable"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
<Space
android:layout_width="@dimen/module_commons_toast_space_between_icon_and_msg"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/module_commons_toast_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawablePadding="@dimen/module_commons_toast_space_between_icon_and_msg"
android:ellipsize="end"
android:gravity="center"
android:maxWidth="@dimen/module_commons_toast_maxWidth"
android:maxLength="20"
android:maxLines="1"
android:textColor="#FFFF"
android:textSize="@dimen/module_commons_toast_textSize"
tools:text="测试测试测试" />
<!-- android:minWidth="@dimen/module_commons_toast_minWidth"-->
</LinearLayout>

View File

@@ -1,13 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="module_commons_toast_marginLeft">50px</dimen>
<dimen name="module_commons_toast_marginRight">50px</dimen>
<dimen name="module_commons_toast_marginLeft">63px</dimen>
<dimen name="module_commons_toast_with_left_drawable_marginLeft">30px</dimen>
<dimen name="module_commons_toast_marginRight">63px</dimen>
<dimen name="module_commons_toast_marginTop">32px</dimen>
<dimen name="module_commons_toast_marginBottom">32px</dimen>
<dimen name="module_commons_toast_with_left_drawable_marginTop">19px</dimen>
<dimen name="module_commons_toast_with_left_drawable_marginBottom">19px</dimen>
<dimen name="module_commons_toast_textSize">40px</dimen>
<dimen name="module_commons_toast_minWidth">698px</dimen>
<dimen name="module_commons_toast_maxWidth">900px</dimen>
<dimen name="module_commons_toast_y_offset">130px</dimen>
<dimen name="module_commons_toast_icon_width">94px</dimen>
<dimen name="module_commons_toast_space_between_icon_and_msg">21px</dimen>
</resources>

View File

@@ -1,11 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="module_commons_toast_marginLeft">30px</dimen>
<dimen name="module_commons_toast_marginRight">30px</dimen>
<dimen name="module_commons_toast_marginLeft">33px</dimen>
<dimen name="module_commons_toast_with_left_drawable_marginLeft">17px</dimen>
<dimen name="module_commons_toast_marginRight">33px</dimen>
<dimen name="module_commons_toast_marginTop">16px</dimen>
<dimen name="module_commons_toast_marginBottom">16px</dimen>
<dimen name="module_commons_toast_with_left_drawable_marginTop">10px</dimen>
<dimen name="module_commons_toast_with_left_drawable_marginBottom">10px</dimen>
<dimen name="module_commons_toast_textSize">22px</dimen>
<dimen name="module_commons_toast_minWidth">371px</dimen>
<dimen name="module_commons_toast_maxWidth">500px</dimen>
<dimen name="module_commons_toast_y_offset">72px</dimen>
<dimen name="module_commons_toast_icon_width">50px</dimen>
<dimen name="module_commons_toast_space_between_icon_and_msg">10px</dimen>
</resources>