Android自定义Toast样式
16lz
2021-12-04
Android自定义Toast样式
public class ToastUtils { private static Toast toast; private static TextView textView; public static void showToast(Context context, String text) { if (toast == null) { LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.item_toast_bg, null); textView = (TextView) view.findViewById(R.id.tv_toast_text); textView.getLayoutParams().width = Utils.getWindowWidth(context); toast = new Toast(context); toast.setGravity(Gravity.BOTTOM, 0, 0);//如果不设置剧中方式,使用系统默认的吐司位置 toast.setDuration(Toast.LENGTH_SHORT); toast.setView(view); } textView.setText(text); toast.show(); }}
更多相关文章
- Android(安卓)封装实现各种样式对话框
- Android中吐司当前电池电量
- Android(安卓)自定义CheckBox 样式
- 关于Android中的各种Dialog
- Android(安卓)单选组合框
- 我的android 第三天 - 自定义Toast
- Android五种Toast显示样式
- Android(安卓)Studio常用对话框
- 面试官:作为Android高级攻城狮,请你解释一下 android:text 到 Text