<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <solid android:color="#99000000" /> <corners android:radius="8dp" /> </shape>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/mbContainer" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginBottom="200dp" android:gravity="bottom|center" android:orientation="vertical" android:paddingLeft="50dp" android:paddingRight="50dp"> <LinearLayout android:id="@+id/toast_linear" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/shape_toastutils_bg" android:gravity="bottom|center" android:orientation="vertical" android:padding="8dp"> <TextView android:id="@+id/mbMessage" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="center_vertical" android:layout_margin="5dp" android:layout_weight="1" android:gravity="center" android:shadowColor="#BB000000" android:shadowRadius="2.75" android:textSize="12sp" android:textColor="#FFFFFFFF" /> </LinearLayout> </LinearLayout>
public static ToastUtils makeText(Context context, String message,
int HIDE_DELAY) {
if (mInstance == null) {
mInstance = new ToastUtils(context);
} else {
// 考虑Activity切换时,Toast依然显示
if (!mContext.getClass().getName().endsWith(context.getClass().getName())) {
mInstance = new ToastUtils(context);
}
}
if (HIDE_DELAY == LENGTH_LONG) {
mInstance.HIDE_DELAY = 2500;
} else {
mInstance.HIDE_DELAY = 1500;
}
mTextView.setText(message);
return mInstance;
}
public static ToastUtils makeText(Context context, int resId, int HIDE_DELAY) {
String mes = "";
try {
mes = context.getResources().getString(resId);
} catch (Resources.NotFoundException e) {
e.printStackTrace();
}
return makeText(context, mes, HIDE_DELAY);
}
public void show() {
if (isShow) {
// 若已经显示,则不再次显示
return;
}
isShow = true;
// 显示动画
mFadeInAnimation = new AlphaAnimation(0.0f, 1.0f);
// 消失动画
mFadeOutAnimation = new AlphaAnimation(1.0f, 0.0f);
mFadeOutAnimation.setDuration(ANIMATION_DURATION);
mFadeOutAnimation
.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// 消失动画后更改状态为 未显示
isShow = false;
}
@Override
public void onAnimationEnd(Animation animation) {
// 隐藏布局,不使用remove方法为防止多次创建多个布局
mContainer.setVisibility(View.GONE);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
mContainer.setVisibility(View.VISIBLE);
mFadeInAnimation.setDuration(ANIMATION_DURATION);
mContainer.startAnimation(mFadeInAnimation);
mHandler.postDelayed(mHideRunnable, HIDE_DELAY);
}
ToastUtils.makeText(context, "消息内容",ToastUtils.LENGTH_SHORT).show();
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有