如何从活动(Activity)中更改片段(Fragment)中视图(View)的可见性?

huangapple go评论83阅读模式
英文:

how to change visibility a view in a fragment from the activity

问题

Sure, here's the translation:

正如标题中所述,如何从活动中更改片段中视图的可见性?

我的代码有一个启动活动和一个片段。我想从活动中更改片段内某个视图的可见性。

如何实现这个?

英文:

As stated in the title how can change visibility a view in a fragment from the activity?

My code has a launch activity and a fragment. I want to change the visibility of a view inside fragment from activity.

How can do this?

答案1

得分: 1

有几种方法。如果您能添加一些代码作为参考就更好了。
第一种方法是在片段中添加一个方法,将可见性设置为“gone”。在您的活动中,您可以通过getSupportFragmentManager().findFragmentById(<container - id>)获取片段的实例,然后调用片段的方法。

第二种方法可以使用接口来实现。

英文:

There can be a couple of ways. It would nice if you add some code for the reference.
1st way would be to have a method in the fragment which would have the set the visibility to gone in fragment. In you activity you can get the instance of the fragment by this getSupportFragmentManager().findFragmentById(&lt;container - id&gt;) and then just call the fragment method.

2nd way could be using interface to this.

huangapple
  • 本文由 发表于 2020年8月1日 02:25:24
  • 转载请务必保留本文链接:https://go.coder-hub.com/63197205.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定