【问题标题】:How to make progress bar of activity visible in fragment如何使片段中的活动进度条可见
【发布时间】:2015-07-01 03:09:08
【问题描述】:

我定义了一个fragment,它被加载到一个activity中,activity布局中有一个进度条,如何让fragment中的进度条可见

【问题讨论】:

  • 因为片段可以像活动一样拥有自己的 xml 布局。您可以在该布局中定义进度条。阅读更多关于片段here

标签: android android-activity fragment android-progressbar


【解决方案1】:

如何使片段中的活动进度条可见

在 Fragment 中使用 getActivity().findViewById 从 Fragments 的父 Activity 访问视图:

Progressbar progressBar = (ProgressBar) 
                getActivity().findViewById(R.id.progress_bar_id);

现在使用progressBar 显示和隐藏Progressbar

注意:确保在Activity中调用setContentView后在FragmentManager中添加Fragments

【讨论】:

    猜你喜欢
    • 2020-10-20
    • 1970-01-01
    • 1970-01-01
    • 2018-10-23
    • 1970-01-01
    • 1970-01-01
    • 2020-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多