Skip to content

Instantly share code, notes, and snippets.

View farooqkhan003's full-sized avatar
🎯
Focusing

Farooq Khan farooqkhan003

🎯
Focusing
  • Lahore, Pakistan
View GitHub Profile
package com.example.farooq.firstappwithkotlin
import android.graphics.Bitmap
/**
* Created by androidtechpoint.blogspot.com on 9/12/2017.
*/
data class MyData(var text:String, var image:Bitmap)
package com.example.farooq.firstappwithkotlin
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/custom_toast_container"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="8dp"
android:background="#DAAA"
>
<ImageView android:src="@drawable/ic_launcher_background"
/**
* 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))
var toast: Toast = Toast(this)
toast.createToast(this, "Hello From Android Tech Point", Gravity.CENTER_VERTICAL, Toast.LENGTH_LONG)