`
chenguandong
  • 浏览: 16223 次
社区版块
存档分类
最新评论

android 自定义toast

 
阅读更多


public static void getMyToast(Context context , int imageResource , String content , int time){
Toast toast = new Toast(context);

toast.setDuration(time);//设置时间
toast.setGravity(Gravity.CENTER, 0,25 ); // 设置出现的位置
//自定义布局
LinearLayout linearLayout = new LinearLayout(context);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
linearLayout.setGravity(Gravity.CENTER_VERTICAL);

ImageView imageView = new ImageView(context);
imageView.setImageResource(R.drawable.ic_launcher);

TextView textView = new TextView(context);
textView.setText(content);

linearLayout.addView(imageView);
linearLayout.addView(textView);


toast.setView(linearLayout);
toast.show();
}
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics