Java Code Examples for android.view.View.setFitsSystemWindows()

The following are Jave code examples for showing how to use setFitsSystemWindows() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: TransparentBar   File: UltimateBar.java   Source Code and License Vote up 7 votes
private void setRootView(Activity activity, boolean fit) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(fit);
            ((ViewGroup)childView).setClipToPadding(fit);
        }
    }
}
 
Example 2
Project: ImmerseMode   File: TlSbTlNbImmerseMode.java   Source Code and License Vote up 7 votes
/**
 * 配置Activity。主要配置Activity的用户视图对状态栏和导航栏的留白
 *
 * @param activity Activity对象,不可为空
 * @throws IllegalStateException
 */
private void setupUserView(@NonNull Activity activity) throws IllegalStateException {
    ViewGroup contentViewGroup = (ViewGroup) activity.findViewById(android.R.id.content);
    final int childViewCount = contentViewGroup.getChildCount();
    if (childViewCount == 0) {
        throw new IllegalStateException("Plz invoke setContentView() method first!");
    } else if (childViewCount > 1) {
        throw new IllegalStateException("Plz set one view in SetContentView() or shouldn't use merge tag!!");
    }

    View userView = contentViewGroup.getChildAt(0);
    userView.setFitsSystemWindows(false);
    ViewGroup.MarginLayoutParams userViewParams = (ViewGroup.MarginLayoutParams) userView.getLayoutParams();
    userViewParams.topMargin += ImmerseGlobalConfig.getInstance().getStatusBarHeight();
    if (mActivityConfig.hasNavigtionBar()) {
        if (mActivityConfig.isNavigationAtBottom()) {
            userViewParams.bottomMargin += mActivityConfig.getNavigationBarHeight();
        } else {
            userViewParams.rightMargin += mActivityConfig.getNavigationBarWidth();
        }
    }
    userView.setLayoutParams(userViewParams);
}
 
Example 3
Project: ImmerseMode   File: TpSbTlNbImmerseMode.java   Source Code and License Vote up 7 votes
/**
 * 配置Activity。主要配置Activity的用户视图对状态栏和导航栏的留白
 *
 * @param activity Activity对象,不可为空
 * @throws IllegalStateException
 */
private void setupUserView(@NonNull Activity activity) throws IllegalStateException {
    ViewGroup contentViewGroup = (ViewGroup) activity.findViewById(android.R.id.content);
    final int childViewCount = contentViewGroup.getChildCount();
    if (childViewCount == 0) {
        throw new IllegalStateException("Plz invoke setContentView() method first!");
    } else if (childViewCount > 1) {
        throw new IllegalStateException("Plz set one view in SetContentView() or shouldn't use merge tag!!");
    }

    View userView = contentViewGroup.getChildAt(0);
    userView.setFitsSystemWindows(false);
    ViewGroup.MarginLayoutParams userViewParams = (ViewGroup.MarginLayoutParams) userView.getLayoutParams();
    userViewParams.topMargin += ImmerseGlobalConfig.getInstance().getStatusBarHeight();
    if (mActivityConfig.hasNavigtionBar()) {
        if (mActivityConfig.isNavigationAtBottom()) {
            userViewParams.bottomMargin += mActivityConfig.getNavigationBarHeight();
        } else {
            userViewParams.rightMargin += mActivityConfig.getNavigationBarWidth();
        }
    }
    userView.setLayoutParams(userViewParams);
}
 
Example 4
Project: OneTwo   File: TimerFragment.java   Source Code and License Vote up 7 votes
public void addChrono() {
    mInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View va = mInflater.inflate(R.layout.list_item_timer, null, false);
    va.setFitsSystemWindows(true);
    Button button = (Button) va.findViewById(R.id.chrono);
    button.setOnClickListener(this);

    TimerBackend timerBackend = new TimerBackend(va, setMiliSeconds,this);

    LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,50,1);
    mLayout.addView(va, lp);
    mTimers.add(timerBackend);

    //turn the first timer if there is only 2 of them
    if (mTimers.size() == 2){
        mTimers.get(0).getmView().setRotation(180);
    }else{
        mTimers.get(0).getmView().setRotation(0);
    }
}
 
Example 5
Project: ImmerseMode   File: TpSbNNbwFCImmerseMode.java   Source Code and License Vote up 7 votes
@NonNull
private View setupContentViewAndStatusBarView(@NonNull Activity activity) throws IllegalStateException {
    ViewGroup contentViewGroup = (ViewGroup) activity.findViewById(android.R.id.content);
    View userView = contentViewGroup.getChildAt(0);
    if (userView == null) {
        throw new IllegalStateException("Plz invode setContentView() method first!");
    }

    userView.setFitsSystemWindows(false);

    mInsetsRect.top = ImmerseGlobalConfig.getInstance().getStatusBarHeight();

    View statusBarView = new View(activity);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mInsetsRect.top);
    contentViewGroup.addView(statusBarView, params);

    return statusBarView;
}
 
Example 6
Project: ImmerseMode   File: TlSbNNbwFCImmerseMode.java   Source Code and License Vote up 7 votes
@NonNull
private View setupStatusBarView(@NonNull Activity activity) throws IllegalStateException {
    ViewGroup contentViewGroup = (ViewGroup) activity.findViewById(android.R.id.content);
    View userView = contentViewGroup.getChildAt(0);
    if (userView == null) {
        throw new IllegalStateException("Plz invode setContentView() method first!");
    }

    userView.setFitsSystemWindows(false);

    mInsetsRect.top = ImmerseGlobalConfig.getInstance().getStatusBarHeight();

    View statusBarView = new View(activity);
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, mInsetsRect.top);
    contentViewGroup.addView(statusBarView, params);

    return statusBarView;
}
 
Example 7
Project: BBSSDK-for-Android   File: StatusBarCompatLollipop.java   Source Code and License Vote up 7 votes
/**
 * set StatusBarColor
 * <p>
 * 1. set Flags to call setStatusBarColor
 * 2. call setSystemUiVisibility to clear translucentStatusBar's Flag.
 * 3. set FitsSystemWindows to false
 */
static void setStatusBarColor(Activity activity, int statusColor, boolean isLight) {
	Window window = activity.getWindow();

	window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
	window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
	window.setStatusBarColor(statusColor);
	int options = View.SYSTEM_UI_FLAG_VISIBLE;
	if (isLight) {
		options = options | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR;
	}
	window.getDecorView().setSystemUiVisibility(options);
	ViewGroup contentview = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
	View childview = contentview.getChildAt(0);
	if (childview != null) {
		childview.setFitsSystemWindows(false);
		childview.requestApplyInsets();
	}
}
 
Example 8
Project: BBSSDK-for-Android   File: StatusBarCompatKitKat.java   Source Code and License Vote up 7 votes
/**
 * set StatusBarColor
 * <p>
 * 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
 * 2. removeFakeStatusBarViewIfExist
 * 3. addFakeStatusBarView
 * 4. addMarginTopToContentChild
 * 5. cancel ContentChild's fitsSystemWindow
 */
static void setStatusBarColor(Activity activity, int statusColor) {
	Window window = activity.getWindow();
	window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

	ViewGroup contentview = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
	View contentchild = contentview.getChildAt(0);
	int statusBarHeight = getStatusBarHeight(activity);

	removeFakeStatusBarViewIfExist(activity);
	addFakeStatusBarView(activity, statusColor, statusBarHeight);
	addMarginTopToContentChild(contentchild, statusBarHeight);

	if (contentchild != null) {
		contentchild.setFitsSystemWindows(false);
	}
}
 
Example 9
Project: Android-UtilCode   File: BarUtils.java   Source Code and License Vote up 6 votes
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 10
Project: stynico   File: StatusBarUtil.java   Source Code and License Vote up 6 votes
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 11
Project: BrotherWeather   File: XStatusBar.java   Source Code and License Vote up 6 votes
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 12
Project: AndroidUtilCode-master   File: BarUtils.java   Source Code and License Vote up 6 votes
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 13
Project: MenuSet   File: ContextMenuDialogFragment.java   Source Code and License Vote up 6 votes
@SuppressLint("NewApi")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.fragment_menu, container, false);
    rootView.setFitsSystemWindows(mMenuParams.isFitsSystemWindow());
    ((ViewGroup) rootView).setClipToPadding(mMenuParams.isClipToPadding());

    initViews(rootView);
    getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    initDropDownMenuAdapter();
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            mDropDownMenuAdapter.menuToggle();
        }
    }, mMenuParams.getAnimationDelay());

    if (mMenuParams.isClosableOutside()) {
        rootView.findViewById(R.id.root).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (isAdded()) {
                    dismiss();
                }
            }
        });
    }
    return rootView;
}
 
Example 14
Project: SliderStatusBar   File: StatusBarUtil.java   Source Code and License Vote up 6 votes
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 15
Project: BBSSDK-for-Android   File: StatusBarCompatKitKat.java   Source Code and License Vote up 6 votes
/**
 * translucentStatusBar
 * <p>
 * 1. set Window Flag : WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
 * 2. removeFakeStatusBarViewIfExist
 * 3. removeMarginTopOfContentChild
 * 4. cancel ContentChild's fitsSystemWindow
 */
static void translucentStatusBar(Activity activity) {
	Window window = activity.getWindow();
	window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

	ViewGroup contentview = (ViewGroup) activity.findViewById(Window.ID_ANDROID_CONTENT);
	View contentchild = contentview.getChildAt(0);

	removeFakeStatusBarViewIfExist(activity);
	removeMarginTopOfContentChild(contentchild, getStatusBarHeight(activity));
	if (contentchild != null) {
		contentchild.setFitsSystemWindows(false);
	}
}
 
Example 16
Project: XFrame   File: XStatusBar.java   Source Code and License Vote up 6 votes
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 17
Project: StatusBarManager   File: StatusBarUtil.java   Source Code and License Vote up 6 votes
/**
 * 设置根布局参数
 */
private static void setRootView(Activity activity) {
    ViewGroup parent = (ViewGroup) activity.findViewById(android.R.id.content);
    for (int i = 0, count = parent.getChildCount(); i < count; i++) {
        View childView = parent.getChildAt(i);
        if (childView instanceof ViewGroup) {
            childView.setFitsSystemWindows(true);
            ((ViewGroup) childView).setClipToPadding(true);
        }
    }
}
 
Example 18
Project: letv   File: ViewCompatICS.java   Source Code and License Vote up 5 votes
public static void setFitsSystemWindows(View view, boolean fitSystemWindows) {
    view.setFitsSystemWindows(fitSystemWindows);
}
 
Example 19
Project: boohee_v5.6   File: ViewCompatICS.java   Source Code and License Vote up 5 votes
public static void setFitsSystemWindows(View view, boolean fitSystemWindows) {
    view.setFitsSystemWindows(fitSystemWindows);
}
 
Example 20
Project: BBSSDK-for-Android   File: BasePage.java   Source Code and License Vote up 5 votes
public void onCreate() {
	if (pageList == null) {
		pageList = new ArrayList<BasePage>();
	}
	pageList.add(this);

	activity.setTheme(ResHelper.getStyleRes(activity, "BBS_AppTheme"));

	Window window = activity.getWindow();
	if (isFullScreen() && Build.VERSION.SDK_INT >= 11) {
		window.getDecorView().setSystemUiVisibility(0x00000100  //SYSTEM_UI_FLAG_LAYOUT_STABLE
				| 0x00000001                                    //SYSTEM_UI_FLAG_LOW_PROFILE
				| 0x00000200                                    //SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
				| 0x00000400                                    //SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
				| 0x00000004                                    //SYSTEM_UI_FLAG_FULLSCREEN
				| 0x00000002                                    //SYSTEM_UI_FLAG_HIDE_NAVIGATION
				| 0x00001000);                                  //SYSTEM_UI_FLAG_IMMERSIVE_STICKY //在导航栏或状态栏区域上滑或下滑时出现导航栏和状态栏,一段时间后自动隐藏
	} else if (Build.VERSION.SDK_INT >= 21) {
		window.clearFlags(0x04000000                                  // LayoutParams.FLAG_TRANSLUCENT_STATUS
				| 0x08000000);                                        // LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
		window.getDecorView().setSystemUiVisibility(0x00000400        // View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
				| 0x00000200                                          // View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
				| 0x00000100);                                        // View.SYSTEM_UI_FLAG_LAYOUT_STABLE
		window.addFlags(0x80000000);                                  // LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
		if (nInitStatusBarColor != null) {
			setStatusBarColor(nInitStatusBarColor);
		} else {
			int statusBarColor = getStatusBarColor();
			if (statusBarColor != 0) {
				setStatusBarColor(statusBarColor);
			}
		}
	}

	View contentView = onCreateView(activity);
	if (contentView != null) {
		if (isUseDefaultBackground() && Build.VERSION.SDK_INT >= 14) {
			contentView.setFitsSystemWindows(true);
		}
		activity.setContentView(contentView);
		onViewCreated(contentView);
	}
	registerLoginoutBroadCastReciever();
}