how to change fragment views programmatically from the parent activity

后端 未结 2 1787
半阙折子戏
半阙折子戏 2021-01-26 00:43

I am having a fragment that contains for example one button, I want to allow the Activity containing the fragment to change this button view like for example color and title or

2条回答
  •  猫巷女王i
    2021-01-26 01:03

    1. You must get you fragment from your activity

    val fragment = supportFragmentManager.findFragmentByTag("tag")
    

    or

    val fragment = supportFragmentManager.findFragmentById(R.id.fragment)
    

    2. Create a method that will do what you wants in you fragment and call this method from the activity

    fragment.hideButton()
    

    or you can use interface

提交回复
热议问题