Skip to content

Instantly share code, notes, and snippets.

@farooqkhan003
Created September 22, 2017 06:31
Show Gist options
  • Save farooqkhan003/42c9aa8071d00076b33f61bb27ae3e66 to your computer and use it in GitHub Desktop.
Save farooqkhan003/42c9aa8071d00076b33f61bb27ae3e66 to your computer and use it in GitHub Desktop.
/**
* Created by android tech point on 9/22/2017.
*/
fun Toast.createToast(context: Context, message:String, gravity:Int, duration:Int){
val inflater:LayoutInflater = context.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
/*first parameter is the layout you made
second parameter is the root view in that xml
*/
val layout = inflater.inflate(R.layout.custom_toast_layout, (context as Activity).findViewById<ViewGroup>(R.id.custom_toast_container))
layout.findViewById<TextView>(R.id.text).text = message
setGravity(gravity, 0, 0)
setDuration(Toast.LENGTH_LONG);
setView(layout);
show()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment