0
0

More than 3 years have passed since last update.

[Kotlin]半透明の操作不可用のViewを表示する。

Posted at

はじめに

ユーザー操作を防ぐために、半透明の膜を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()
        }
    }

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0