Android P visibilityawareimagebutton.setVisibility can only be called from the same library group

前端 未结 8 1832
不思量自难忘°
不思量自难忘° 2020-12-23 20:00

I\'m trying to use the new Android P FloatingActionButton that\'s part of the com.google.android.material.floatingactionbutton.FloatingActionButton and I\'m get

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-23 20:35

    For Kotlin I have an extension method

    fun viewsVisibility(visibility: Int, vararg views: View) {
        for (view in views) { view.visibility = visibility }
    }
    

    Then in then in the code you can do the following

    viewsVisibility(View.VISIBLE, demoFab) 
    viewsVisibility(View.GONE, demoFab)
    viewsVisibility(View.INVISIBLE, demoFab, addFab, removeFab)
    

    The error will be gone and this gives the flexibility for any visibility state along with taking in a list of views to handle. There are a lot of times I need to handle more than one view at a time as shown in the final example line.

提交回复
热议问题