如何通过代码设置 Fragment 标签? [英] How to set a Fragment tag by code?
问题描述
我没有在 Fragment
类中找到类似 setTag(String tagName)
的方法.我发现设置 Fragment
标签的唯一方法是执行 FragmentTransaction
并将标签名称作为参数传递.
I haven't found something like setTag(String tagName)
method in the Fragment
class. The only way to set a Fragment
tag that I have found is by doing a FragmentTransaction
and passing a tag name as parameter.
这是通过代码显式设置 Fragment
标签的唯一方法吗?
Is this the only way to explicitly set a Fragment
tag by code?
推荐答案
是的.所以唯一的方法是在交易时间,例如使用 add
、replace
或作为布局的一部分.
Yes. So the only way is at transaction time, e.g. using add
, replace
, or as part of the layout.
我通过检查兼容性来源确定了这一点,因为我在过去的某个时候曾短暂地寻找过类似的东西.
I determined this through an examination of the compatibility sources as I briefly looked for similar at some point in the past.
这篇关于如何通过代码设置 Fragment 标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!