Created
September 22, 2017 06:31
-
-
Save farooqkhan003/42c9aa8071d00076b33f61bb27ae3e66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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