码迷,mamicode.com
首页 > 移动开发 > 详细

Android判断Navigation Bar 是否透明

时间:2014-05-15 18:15:56      阅读:631      评论:0      收藏:0      [点我收藏+]

标签:navigationbar   flag_translucent_nav   windowtranslucentnav   setflag   

设置Navigation Bar 透明

getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
或者Theme中添加  <item name="android:windowTranslucentNavigation">true</item>

  /**
     * Convenience function to set the flag bits as specified in flags, as
     * per {@link #setFlags}.
     * @param flags The flag bits to be set.
     * @see #setFlags
     * @see #clearFlags
     */
    public void addFlags(int flags) {
        setFlags(flags, flags);
    }


/**
     * Set the flags of the window, as per the
     * {@link WindowManager.LayoutParams WindowManager.LayoutParams}
     * flags.
     * 
     * <p>Note that some flags must be set before the window decoration is
     * created (by the first call to
     * {@link #setContentView(View, android.view.ViewGroup.LayoutParams)} or
     * {@link #getDecorView()}:
     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_IN_SCREEN} and
     * {@link WindowManager.LayoutParams#FLAG_LAYOUT_INSET_DECOR}.  These
     * will be set for you based on the {@link android.R.attr#windowIsFloating}
     * attribute.
     *
     * @param flags The new window flags (see WindowManager.LayoutParams).
     * @param mask Which of the window flag bits to modify.
     * @see #addFlags
     * @see #clearFlags
     */
    public void setFlags(int flags, int mask) {
        final WindowManager.LayoutParams attrs = getAttributes();
        attrs.flags = (attrs.flags&~mask) | (flags&mask);
        if ((mask&WindowManager.LayoutParams.FLAG_NEEDS_MENU_KEY) != 0) {
            attrs.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_SET_NEEDS_MENU_KEY;
        }
        mForcedWindowFlags |= mask;
        if (mCallback != null) {
            mCallback.onWindowAttributesChanged(attrs);
        }
    }

其中:
attrs.flags = (attrs.flags&~mask) | (flags&mask);

谁能给解释一下这行代码的意思?以前学的都忘记了

so 

	public boolean existFlag(int flags){
	    WindowManager.LayoutParams attrs= getWindow().getAttributes();
	    if(attrs.flags ==( (attrs.flags&~flags) | (flags&flags))){
	    	return true;
	    }
	    return false;
	}

KitKat上验证通过。


Android判断Navigation Bar 是否透明,布布扣,bubuko.com

Android判断Navigation Bar 是否透明

标签:navigationbar   flag_translucent_nav   windowtranslucentnav   setflag   

原文地址:http://blog.csdn.net/huangyanan1989/article/details/25879887

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!