如何在特定的碎片中隐藏操作栏

8

我有A、B、C、D四个碎片。我想在D碎片中隐藏操作栏。

我尝试了getActivity().getActionBar().hide();,但它没有起作用。

public class Profile extends Fragment {

    public Profile() {
        // Required empty public constructor
    }

    public static Profile newInstance(int instance) {
        Bundle args = new Bundle();
        args.putInt("argsInstance", instance);
        Profile profile = new Profile();
        profile.setArguments(args);
        return profile;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {

        getActivity().getActionBar().hide();


        // Inflate the layout for this fragment
        View profile = inflater.inflate(R.layout.fragment_profile, container, false);

        return profile;


    }

}

1
如果你正在使用AppCompatActivity(你应该这样做),那么这是对我有效的解决方案:((AppCompatActivity) getActivity()).getSupportActionBar().hide(); - Ram Koti
请检查上面的行。 - Ram Koti
1个回答

6

我曾经有同样的问题并一直在寻找答案,现在终于找到了!

以下是答案,希望能帮到你:

// Hide the status bar.
int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
view.setSystemUiVisibility(uiOptions);
// Remember that you should never show the action bar if the
// status bar is hidden, so hide that too if necessary.
((AppCompatActivity)getActivity()).getSupportActionBar().hide();

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接