package com.example.administrator.androidjs.kt
import android.app.Activity
import android.content.Context
import android.util.SparseArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.Toast
import com.bumptech.glide.Glide
import org.jetbrains.anko.themedImageSwitcher
/**
* Created by Administrator on 2018/6/30.
*/
fun Context.toast(message: CharSequence, duration: Int = Toast.LENGTH_SHORT) {
Toast.makeText(this, message, duration).show()
}
fun Activity.toast(message: CharSequence, duration: Int = Toast.LENGTH_SHORT){
Toast.makeText(this, message, duration).show()
}
fun ImageView.LoadUrl(url:String){
Glide.with(this).load(url).into(this)
}
fun ViewGroup.inflate(layoutRes: Int): View {
return LayoutInflater.from(context).inflate(layoutRes, this, false)
}
fun<T : View> View.findViewOften(viewId:Int): T {
var viewHolder: SparseArray<View> = tag as? SparseArray<View> ?: SparseArray()
tag = viewHolder
var childView: View? = viewHolder.get(viewId)
if(null== childView) {
childView = findViewById(viewId)
viewHolder.put(viewId, childView)
}
return childView as T
}
``package com.example.administrator.androidjs.kt.expand
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import com.example.administrator.androidjs.R
import kotlinx.android.synthetic.main.page1.*
/**
* Created by Administrator on 2018/6/30.
*/
class ExpandMethodPage:AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.page1)
Toast("你好")
iv.LoadUrl("https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1530376540089&di=9eb61ef231c2979ce037b13d21795b3d&imgtype=0&src=http%3A%2F%2Fimgsrc.baidu.com%2Fimgad%2Fpic%2Fitem%2Feaf81a4c510fd9f900630df72f2dd42a2834a43c.jpg")
}
}
让Android开发更愉快的Kotlin 扩展函数和高阶函数学习篇
最新推荐文章于 2024-05-22 12:39:31 发布