论坛首页 移动开发技术论坛

使用系统样式的自定义图片加文字的Toast

浏览 2573 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2011-08-29   最后修改:2011-08-29

 

使用系统样式的自定义图片加文字的Toast。废话不多说,直接上代码:

Toast toast = Toast.makeText(this, null, Toast.LENGTH_LONG);
LinearLayout layout = (LinearLayout)toast.getView();
layout.setOrientation(LinearLayout.HORIZONTAL);
		
ImageView imgView = new ImageView(this);
imgView.setImageResource(R.drawable.succ);
layout.addView(imgView);
		
TextView tv = new TextView(this);
tv.setLayoutParams(new  LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT));
tv.setGravity(Gravity.CENTER_VERTICAL);
tv.setPadding(10, 0, 0, 0);
tv.setText(R.string.mood_fine);
layout.addView(tv);
toast.show();

 附件是效果图


  • 大小: 5 KB
论坛首页 移动开发技术版

跳转论坛:
Global site tag (gtag.js) - Google Analytics