先看看两篇文章
Android 更改 Toast 的默认位置
android Toast大全(五种情形)建立属于你自己的Toast
Toast Notifications的API

默认效果的代码

Toast.makeText(MainActivity.this,"默认样式",Toast.LENGTH_SHORT).show();

自定义显示位置效果

private Toast toast; toast=  Toast.makeText(MainActivity.this, pickers.getShowConetnt(), Toast.LENGTH_SHORT);            toast.setGravity(Gravity.TOP, 0, 0);            toast.show();//setGravity参数一个Gravity常量,一个x方向偏移值和一个y方向偏移值。//如果你想要向右移动,增加第二个参数的值;增加第三个参数的值向下移动。

带图片的Toast

private Toast toast; toast=  Toast.makeText(MainActivity.this, pickers.getShowConetnt(), Toast.LENGTH_SHORT);   toast.setGravity(Gravity.CENTER, 0, 0);   LinearLayout toastView = (LinearLayout) toast.getView();   ImageView imageCodeProject = new ImageView(getApplicationContext());   imageCodeProject.setImageResource(R.drawable.icon);   toastView.addView(imageCodeProject, 0);   toast.show();

完全自定义效果

LayoutInflater inflater = getLayoutInflater();   View layout = inflater.inflate(R.layout.custom,     (ViewGroup) findViewById(R.id.llToast));   ImageView image = (ImageView) layout     .findViewById(R.id.tvImageToast);   image.setImageResource(R.drawable.icon);   TextView title = (TextView) layout.findViewById(R.id.tvTitleToast);   title.setText("Attention");   TextView text = (TextView) layout.findViewById(R.id.tvTextToast);   text.setText("完全自定义Toast");   toast = new Toast(getApplicationContext());   toast.setGravity(Gravity.RIGHT | Gravity.TOP, 12, 40);   toast.setDuration(Toast.LENGTH_LONG);   toast.setView(layout);   toast.show();

完.

更多相关文章

  1. --------------------【Android】跑马灯效果(文字滚动)
  2. Activity 属性设置参数说明
  3. Android:实现一种浮动选择菜单的效果
  4. Android中ImageButton自定义按钮的按下效果的代码实现方法,附网上
  5. Android使用okhttp框架实现带参数Get和Post请求(附服务端完整代码
  6. android 图片切换,仿百叶窗效果

随机推荐

  1. Android聊天室(源码)
  2. Android中webview的使用
  3. Android Studio设置界面风格和字体大小
  4. 移除Android中的安全模式
  5. android ScreenshotClient 接口截屏幕
  6. Google Android's Gingerbread Update Co
  7. android-google开源资源
  8. 自定义dialog的style属性说明
  9. android之相机 VideoSource和AudioSource
  10. Android文件存储读写