当前位置:操作系统 > 安卓/Android >>

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();


摘自  I'm Different 
补充:移动开发 , Android ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,