简体   繁体   English

覆盖片段内的活动工具栏(并在片段被销毁时恢复)

[英]Override the activity toolbar inside a fragment (and restore when the fragment is destroyed)

I'm trying to hide the activity toolbar inside a fragment when it is attached to the screen. 当它连接到屏幕时,我试图将活动工具栏隐藏在一个片段内。 And restore the toolbar when the fragment is detached. 并在片段分离后还原工具栏。

How can I achieve this in a smooth way? 我怎样才能顺利地做到这一点?

In your fragment you can do it by 在您的片段中,您可以通过

@Override
public void onResume() {
    super.onResume();
    ((AppCompatActivity)getActivity()).getSupportActionBar().hide();
    //Replace AppCompateActivity with the activity class you used.
}

@Override
public void onDetach(){
    super.onDetach();
    ((AppCompatActivity)getActivity()).getSupportActionBar().show();
    //Replace AppCompateActivity with the activity class you used.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM