はじめに
ユーザー操作を防ぐために、半透明の膜をActivity画面の最前面に作成する。
ソース
kotlin.kt
var vwFilm: View? = null
protected fun showFilm(){
if(vwFilm == null) {
this.vwFilm = View(this)
vwFilm?.setBackgroundColor(Color.parseColor("#66FF00FF"))
addContentView(vwFilm, ViewGroup.LayoutParams(base.width, base.height))
vwFilm?.bringToFront()
//イベントを下の要素に貫通させないために空リスナーをセット
vwFilm?.setOnClickListener { }
}else{
vwFilm?.isVisible = true
}
}
protected fun hideFilm(){
//メインスレッドを明示しておく。
GlobalScope.launch(Dispatchers.Main) {
vwFilm?.isVisible = false
}
}
fun exec(){
showFilm()
thread {
Thread.sleep(2000)
hideFilm()
}
}