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

使用系统样式的自定义图片加文字的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();

 附件是效果图


你可能感兴趣的:(android,图片,toast,文字,自定义Toast)