请告诉我这是否有帮助:
SystemUiHider.getInstance(activity, anchorView, flags).hide();
这段代码的作用是隐藏系统UI界面,其中activity表示当前活动的页面,anchorView表示锚定的视图,flags表示标志位。
* @param activity
* The activity whose window's system UI should be controlled by
* this class.
* @param anchorView
* The view on which {@link View#setSystemUiVisibility(int)} will
* be called.
* @param flags
* Either 0 or any combination of {@link #FLAG_FULLSCREEN},
* {@link #FLAG_HIDE_NAVIGATION}, and
* {@link #FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES}.
*/
import android.app.Activity;
import android.os.Build;
import android.view.View;
public abstract class SystemUiHider {
public static final int FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES = 0x1;
public static final int FLAG_FULLSCREEN = 0x2;
public static final int FLAG_HIDE_NAVIGATION = FLAG_FULLSCREEN | 0x4;
protected Activity mActivity;
protected View mAnchorView;
protected int mFlags;
protected OnVisibilityChangeListener mOnVisibilityChangeListener = sDummyListener;
public static SystemUiHider getInstance(Activity activity, View anchorView,
int flags) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
return new SystemUiHiderHoneycomb(activity, anchorView, flags);
} else {
return new SystemUiHiderBase(activity, anchorView, flags);
}
}
protected SystemUiHider(Activity activity, View anchorView, int flags) {
mActivity = activity;
mAnchorView = anchorView;
mFlags = flags;
}
public abstract void setup();
public abstract boolean isVisible();
public abstract void hide();
public abstract void show();
public void toggle() {
if (isVisible()) {
hide();
} else {
show();
}
}
public void setOnVisibilityChangeListener(
OnVisibilityChangeListener listener) {
if (listener == null) {
listener = sDummyListener;
}
mOnVisibilityChangeListener = listener;
}
private static OnVisibilityChangeListener sDummyListener = new OnVisibilityChangeListener() {
@Override
public void onVisibilityChange(boolean visible) {
}
};
public interface OnVisibilityChangeListener {
public void onVisibilityChange(boolean visible);
}
}
import android.app.Activity;
import android.view.View;
import android.view.WindowManager;
public class SystemUiHiderBase extends SystemUiHider {
private boolean mVisible = true;
protected SystemUiHiderBase(Activity activity, View anchorView, int flags) {
super(activity, anchorView, flags);
}
@Override
public void setup() {
if ((mFlags & FLAG_LAYOUT_IN_SCREEN_OLDER_DEVICES) == 0) {
mActivity.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
| WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
}
@Override
public boolean isVisible() {
return mVisible;
}
@Override
public void hide() {
if ((mFlags & FLAG_FULLSCREEN) != 0) {
mActivity.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
mOnVisibilityChangeListener.onVisibilityChange(false);
mVisible = false;
}
@Override
public void show() {
if ((mFlags & FLAG_FULLSCREEN) != 0) {
mActivity.getWindow().setFlags(0,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
mOnVisibilityChangeListener.onVisibilityChange(true);
mVisible = true;
}
}
import android.annotation.TargetApi;
import android.app.Activity;
import android.os.Build;
import android.view.View;
import android.view.WindowManager;
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public class SystemUiHiderHoneycomb extends SystemUiHiderBase {
private int mShowFlags;
private int mHideFlags;
private int mTestFlags;
private boolean mVisible = true;
protected SystemUiHiderHoneycomb(Activity activity, View anchorView,
int flags) {
super(activity, anchorView, flags);
mShowFlags = View.SYSTEM_UI_FLAG_VISIBLE;
mHideFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
mTestFlags = View.SYSTEM_UI_FLAG_LOW_PROFILE;
if ((mFlags & FLAG_FULLSCREEN) != 0) {
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
}
if ((mFlags & FLAG_HIDE_NAVIGATION) != 0) {
mShowFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
mHideFlags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
mTestFlags |= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
}
}
@Override
public void setup() {
mAnchorView
.setOnSystemUiVisibilityChangeListener(mSystemUiVisibilityChangeListener);
}
@Override
public void hide() {
mAnchorView.setSystemUiVisibility(mHideFlags);
}
@Override
public void show() {
mAnchorView.setSystemUiVisibility(mShowFlags);
}
@Override
public boolean isVisible() {
return mVisible;
}
private View.OnSystemUiVisibilityChangeListener mSystemUiVisibilityChangeListener = new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int vis) {
if ((vis & mTestFlags) != 0) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mActivity.getActionBar().hide();
mActivity.getWindow().setFlags(
WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
mOnVisibilityChangeListener.onVisibilityChange(false);
mVisible = false;
} else {
mAnchorView.setSystemUiVisibility(mShowFlags);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
mActivity.getActionBar().show();
mActivity.getWindow().setFlags(0,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
mOnVisibilityChangeListener.onVisibilityChange(true);
mVisible = true;
}
}
};
}