使用导航抽屉在AppCompatActivity上使用Fragment全屏

时间:2016-01-08 04:27:59

标签: android android-activity fragment

我有一个带导航抽屉的主AppCompatActivity。主AppCompatActivity不是全屏,因此您仍然可以在屏幕顶部看到状态栏。但是,当片段显示给用户时,我确实希望片段占据整个屏幕。这有可能,如果是这样的话?如果有的话,请提供任何示例的链接。先谢谢你。

1 个答案:

答案 0 :(得分:0)

在您Activity中执行此类实施:

SystemUiHider mUiHider = null;

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

    //go full screen with no title
    this.requestWindowFeature(Window.FEATURE_PROGRESS); //show progress on loadup
    this.requestWindowFeature(Window.FEATURE_NO_TITLE); 
    this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 

    setContentView(R.layout.activity_main);
    final RelativeLayout mainLayout = (RelativeLayout)this.findViewById(R.id.mainLayout);
    mUiHider = SystemUiHider.getInstance(this, mainLayout, SystemUiHider.FLAG_HIDE_NAVIGATION);
    mUiHider.setup();
    mUiHider.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
        @Override
        @TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
        public void onVisibilityChange(boolean visible) {
            if (visible) {
                mUiHider.hide(); 
                final Handler mHideHandler = new Handler();
                final Runnable mHideRunnable = new Runnable() {
                    @Override
                    public void run() {
                        mUiHider.hide();
                    }
                };
                mHideHandler.removeCallbacks(mHideRunnable);
                mHideHandler.postDelayed(mHideRunnable, 1000); 
            }
        }
    });
    mUiHider.hide();
}