直播网站源码Android自定义toast显示效果
编码实现

创新互联公司专业为企业提供定陶网站建设、定陶做网站、定陶网站设计、定陶网站制作等企业网站建设、网页设计与制作、定陶企业网站模板建站服务,十余年定陶做网站经验,不只是建网站,更提供有价值的思路和整体网络服务。
**ToastUtils.java**
public class ToastUtils {
private static Toast mToast;
public static void showShortText(String text){
showText(text,Toast.LENGTH_SHORT);
}
public static void showLongText(String text){
showText(text,Toast.LENGTH_LONG);
}
public static void showText(String text,int duration){
if (TextUtils.isEmpty(text)){
return;
}
TextView tvText;
if (mToast == null){
mToast = Toast.makeText(MyApplication.getContext(), "", Toast.LENGTH_SHORT);
final View toastLayout = ((LayoutInflater) MyApplication.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.toast_layout, null);
tvText = toastLayout.findViewById(R.id.toast_text);
mToast.setView(toastLayout);
}else {
mToast.cancel();
mToast = Toast.makeText(MyApplication.getContext(), "", Toast.LENGTH_SHORT);
final View toastLayout = ((LayoutInflater) MyApplication.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE))
.inflate(R.layout.toast_layout, null);
tvText = toastLayout.findViewById(R.id.toast_text);
mToast.setView(toastLayout);
}
mToast.setDuration(duration);
tvText.setText(text);
mToast.show();
}
// 普通方法.....
public static void showToast(String msg, int duration) {
mToast = Toast.makeText(MyApplication.getContext(), "", duration);
mToast.setText(msg);
mToast.show();
}
}
```
**toast_layout.xml**
```clike
**bg_toast**
使用
ToastUtils.showShortText("1111");
总结
自定义背景效果还是比较简单的,有利于统一机型效果,不是很复杂。主要是从toast源码提供的api我们进行了相应的扩展,容易的实现是建立在对原理的理解与运用上的,多多注重基础,一起前进。
当前名称:直播网站源码Android自定义toast显示效果
网站网址:http://www.jxjierui.cn/article/ggoghc.html


咨询
建站咨询
