makeText(Context context, int resId, int duration)
makeText(Context context, CharSequence text, int duration)
Toast toast = Toast.makeText(ToastDemoActivity.this, "这是一个普通的Toast!", Toast.LENGTH_SHORT); toast.show();
setGravity(int gravity, int xOffset, int yOffset)
setMargin(float horizontalMargin, float verticalMargin)
// 设置Toast显示位置(起点位置,水平向右位移,垂直向下位移) toast.setGravity(Gravity.TOP | Gravity.LEFT, 0, 200); // Toast显示位置,以横向和纵向的百分比计算,参数均为float类型(水平位移正右负左,竖直位移正上负下) toast.setMargin(-0.5f, 0f);
// 带图片的Toast
Button btn2 = (Button) findViewById(R.id.toast2);
btn2.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
// 定义一个Toast
Toast toast = Toast.makeText(ToastDemoActivity.this, "这是一个代图片的Toast!", Toast.LENGTH_LONG);
// 定义一个ImageView
ImageView imageView = new ImageView(ToastDemoActivity.this);
imageView.setImageResource(R.drawable.icon);
// 获得Toast的View
View toastView = toast.getView();
// 定义一个Layout,这里是Layout
LinearLayoutlinear Layout = new LinearLayout(ToastDemoActivity.this);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
// 将ImageView和ToastView合并到Layout中
linearLayout.addView(imageView);
linearLayout.addView(toastView);
// 替换掉原有的ToastView
toast.setView(linearLayout);
toast.show();
}
});
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有