读书人

Toast 的几种展示方法

发布时间: 2012-06-26 10:04:13 作者: rapoo

Toast 的几种显示方法

Toast toast = new Toast(this); ImageView view = new ImageView(this); view.setImageResource(R.drawable.icon); toast.setView(view); toast.show();//第二种图片加文字Toast toast = Toast.makeText(this, "lalalal", Toast.LENGTH_LONG); View textView = toast.getView(); LinearLayout lay = new LinearLayout(this); lay.setOrientation(LinearLayout.HORIZONTAL); ImageView view = new ImageView(this); view.setImageResource(R.drawable.icon); lay.addView(view); lay.addView(textView); toast.setView(lay); 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();

读书人网 >移动开发

热点推荐