如何显示来自一个片段的自定义动作条仅查看 [英] How to show a custom actionbar view from one fragment only

查看:114
本文介绍了如何显示来自一个片段的自定义动作条仅查看的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的应用程序要求的自定义操作栏视图从一个片段只(登陆页面片段)所示。问题是,当用户浏览到其他片段这个动作栏出现。有没有办法做到这一点,而无需禁用的自定义视图中的每个片段呢?

I have a requirement for my app that a custom action bar view be shown from one fragment only (the landing page fragment). The problem is that this action bar is appearing when the user navigates to other fragments. Is there a way to do this without disabling custom view on every fragment?

感谢

推荐答案

对于这一问题,只能说明动作条的一个片段,而不显示在所有其他片段,解决方案是很容易的:

For this issue, only show actionbar for one fragment without show on all other fragments, solution could be very easy:

在你的活动承载您的片段:

In your activity that hosts your fragments:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ... ...

    // for API >= 11
    getActionBar.hide();
    // for API < 11
    getSupportActionBar().hide();

    ... ...
}

然后,在你想显示动作条片段:

Then in the fragment that you want to show actionbar:

@Override
public void  onAttach(Activity activity){
    activity.getActionBar().show(); //getSupportActionBar() for API<11

}

@Override
public void onHiddenChanged(boolean hidden) {
    super.onHiddenChanged(hidden);
    if (hidden) {
       getActivity().getActionBar().hide(); //getSupportActionBar() for API<11
    } else {
       getActivity().getActionBar().show(); //getSupportActionBar() for API<11
}

}

这篇关于如何显示来自一个片段的自定义动作条仅查看的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆