How to set a Fragment tag by code?

前端 未结 8 2344
我寻月下人不归
我寻月下人不归 2020-12-01 02:26

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 fo

相关标签:
8条回答
  • 2020-12-01 03:07

    You can add the tag as a property for the Fragment arguments. It will be automatically restored if the fragment is destroyed and then recreated by the OS.

    Example:-

        final Bundle args = new Bundle();
        args.putString("TAG", "my tag");
        fragment.setArguments(args);
    
    0 讨论(0)
  • 2020-12-01 03:13

    You can provide a tag inside your activity layout xml file.

    Supply the android:tag attribute with a unique string.

    Just as you would assign an id in a layout xml.

        android:tag="unique_tag"
    

    link to developer guide

    0 讨论(0)
提交回复
热议问题