原文地址:https://rongi.github.io/kotlin-blog/kotlin/2017/06/28/toast.html

 

Google的时候翻到了一个别人用kotlin实现的toast工具类感觉很棒,特别记录一下:

实现

fun Any.toast(context: Context, duration: Int = Toast.LENGTH_SHORT): Toast {  return Toast.makeText(context, this.toString(), duration).apply { show() }}

用法:

"This is my string".toast(context)
"click on ${position.name}".toast(context)

 

原文地址:https://rongi.github.io/kotlin-blog/kotlin/2017/06/28/toast.html

 

 

 

更多相关文章

  1. Android(安卓)开源框架
  2. android条形码二维码
  3. android repo/git server 建立过程(1)
  4. 在Android中引入Java8的lambda表达式
  5. Android(安卓)SDK 在线更新镜像服务器资源
  6. android UI开源项目
  7. 一些android错误
  8. Android(安卓)VideoView通过Intent.ACTION_VIEW播放视频(4)
  9. Android(安卓)VideoView如何播放RTSP的流

随机推荐

  1. android启动优化
  2. Android(安卓)菜单资源
  3. Android之VideoView窗口/全屏播放
  4. Android—文字轮播
  5. Android(安卓)4.4 上实现透明导航栏和状
  6. Android(安卓)Progressbar进度条显示
  7. android软键盘问题
  8. Android(安卓)sqlite例子 有外键的使用
  9. android中颜色对应的值
  10. Android(安卓)Studio编译问题:ProcessExce