能帮忙解释一下下面一段Android程序吗
关于Toast完全自定义效果:代码LayoutInflaterinflater=getLayoutInflater();Viewlayout=inflater.infla...
关于Toast完全自定义效果:
代码LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom, (ViewGroup) findViewById(R.id.llToast)); ImageView image = (ImageView) layout .findViewById(R.id.tvImageToast); image.setImageResource(R.drawable.icon); TextView title = (TextView) layout.findViewById(R.id.tvTitleToast); title.setText("Attention"); TextView text = (TextView) layout.findViewById(R.id.tvTextToast); text.setText("完全自定义Toast"); toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); 展开
代码LayoutInflater inflater = getLayoutInflater(); View layout = inflater.inflate(R.layout.custom, (ViewGroup) findViewById(R.id.llToast)); ImageView image = (ImageView) layout .findViewById(R.id.tvImageToast); image.setImageResource(R.drawable.icon); TextView title = (TextView) layout.findViewById(R.id.tvTitleToast); title.setText("Attention"); TextView text = (TextView) layout.findViewById(R.id.tvTextToast); text.setText("完全自定义Toast"); toast = new Toast(getApplicationContext()); toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40); toast.setDuration(Toast.LENGTH_LONG); toast.setView(layout); toast.show(); 展开
1个回答
展开全部
//把UI文件放到一个空的的view里面
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom,(ViewGroup) findViewById(R.id.llToast));
//定义放进UI界面的view里面的子空间
ImageView image = (ImageView) layout
.findViewById(R.id.tvImageToast);
image.setImageResource(R.drawable.icon);
TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);
title.setText("Attention");
TextView text = (TextView) layout.findViewById(R.id.tvTextToast);
text.setText("完全自定义Toast");
//设置TOAST
toast = new Toast(getApplicationContext()); //创建新对象
toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40); //设置Toast显示位置
toast.setDuration(Toast.LENGTH_LONG); //设置Toast显示时间长短类型
toast.setView(layout); //把上面定义好的view添加到toast里面
toast.show(); //显示toast
LayoutInflater inflater = getLayoutInflater();
View layout = inflater.inflate(R.layout.custom,(ViewGroup) findViewById(R.id.llToast));
//定义放进UI界面的view里面的子空间
ImageView image = (ImageView) layout
.findViewById(R.id.tvImageToast);
image.setImageResource(R.drawable.icon);
TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);
title.setText("Attention");
TextView text = (TextView) layout.findViewById(R.id.tvTextToast);
text.setText("完全自定义Toast");
//设置TOAST
toast = new Toast(getApplicationContext()); //创建新对象
toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40); //设置Toast显示位置
toast.setDuration(Toast.LENGTH_LONG); //设置Toast显示时间长短类型
toast.setView(layout); //把上面定义好的view添加到toast里面
toast.show(); //显示toast
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询