android.view.Window#getNavigationBarColor ( )源码实例Demo

下面列出了android.view.Window#getNavigationBarColor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: LokiBoard-Android-Keylogger   文件: LatinIME.java
private void setNavigationBarColor() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && mSettings.getCurrent().mUseMatchingNavbarColor) {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        final int keyboardColor = Settings.readKeyboardColor(prefs, this);
        final Window window = getWindow().getWindow();
        if (window == null) {
            return;
        }
        mOriginalNavBarColor = window.getNavigationBarColor();
        window.setNavigationBarColor(keyboardColor);

        final View view = window.getDecorView();
        mOriginalNavBarFlags = view.getSystemUiVisibility();
        if (ResourceUtils.isBrightColor(keyboardColor)) {
            view.setSystemUiVisibility(mOriginalNavBarFlags | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
        } else {
            view.setSystemUiVisibility(mOriginalNavBarFlags & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
        }
    }
}
 
源代码2 项目: cronet   文件: ApiCompatibilityUtils.java
/**
 * @see android.view.Window#setStatusBarColor(int color).
 */
public static void setStatusBarColor(Window window, int statusBarColor) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) return;

    // If both system bars are black, we can remove these from our layout,
    // removing or shrinking the SurfaceFlinger overlay required for our views.
    // This benefits battery usage on L and M.  However, this no longer provides a battery
    // benefit as of N and starts to cause flicker bugs on O, so don't bother on O and up.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O && statusBarColor == Color.BLACK
            && window.getNavigationBarColor() == Color.BLACK) {
        window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    } else {
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    }
    window.setStatusBarColor(statusBarColor);
}
 
源代码3 项目: simple-keyboard   文件: LatinIME.java
private void setNavigationBarColor() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && mSettings.getCurrent().mUseMatchingNavbarColor) {
        final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
        final int keyboardColor = Settings.readKeyboardColor(prefs, this);
        final Window window = getWindow().getWindow();
        if (window == null) {
            return;
        }
        mOriginalNavBarColor = window.getNavigationBarColor();
        window.setNavigationBarColor(keyboardColor);

        final View view = window.getDecorView();
        mOriginalNavBarFlags = view.getSystemUiVisibility();
        if (ResourceUtils.isBrightColor(keyboardColor)) {
            view.setSystemUiVisibility(mOriginalNavBarFlags | View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
        } else {
            view.setSystemUiVisibility(mOriginalNavBarFlags & ~View.SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR);
        }
    }
}
 
源代码4 项目: scene   文件: ActivityStatusRecord.java
public static ActivityStatusRecord newInstance(Activity activity) {
    ActivityStatusRecord record = new ActivityStatusRecord();
    Window window = activity.getWindow();
    View decorView = window.getDecorView();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        record.mStatusBarColor = window.getStatusBarColor();
        record.mNavigationBarColor = window.getNavigationBarColor();
    }
    record.mSystemUiVisibility = decorView.getSystemUiVisibility();
    record.mSoftInputMode = window.getAttributes().softInputMode;
    record.mWindowFlags = window.getAttributes().flags;
    record.mRequestedOrientation = activity.getRequestedOrientation();
    return record;
}
 
源代码5 项目: DevUtils   文件: BarUtils.java
/**
 * 获取 Navigation Bar 颜色
 * @param window {@link Window}
 * @return Navigation Bar 颜色
 */
public static int getNavBarColor(final Window window) {
    if (window != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        return window.getNavigationBarColor();
    }
    return -1;
}
 
源代码6 项目: 365browser   文件: ApiCompatibilityUtils.java
/**
 * @see android.view.Window#setStatusBarColor(int color).
 */
public static void setStatusBarColor(Window window, int statusBarColor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // If both system bars are black, we can remove these from our layout,
        // removing or shrinking the SurfaceFlinger overlay required for our views.
        if (statusBarColor == Color.BLACK && window.getNavigationBarColor() == Color.BLACK) {
            window.clearFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        } else {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        }
        window.setStatusBarColor(statusBarColor);
    }
}
 
源代码7 项目: NightOwl   文件: NavBarObserver.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public NavBarObserver(Activity activity, TypedArray a, int attr) {
    Window window = activity.getWindow();
    mNavigationBarColor = window.getNavigationBarColor();
    mNavigationBarColorNight = a.getColor(attr,mNavigationBarColor);
}
 
源代码8 项目: Dashchan   文件: ExpandedScreen.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ExpandedScreen(Activity activity, boolean enabled) {
	this.activity = activity;
	statusBar = new StatusBarController(activity);
	navigationBar = new NavigationBarController();
	Resources resources = activity.getResources();
	Window window = activity.getWindow();
	boolean fullScreenLayoutEnabled;
	if (C.API_LOLLIPOP) {
		fullScreenLayoutEnabled = true;
	} else if (C.API_KITKAT) {
		int resId = resources.getIdentifier("config_enableTranslucentDecor", "bool", "android");
		fullScreenLayoutEnabled = resId != 0 && resources.getBoolean(resId);
	} else {
		fullScreenLayoutEnabled = false;
	}
	expandingEnabled = enabled;
	this.fullScreenLayoutEnabled = fullScreenLayoutEnabled;
	float density = ResourceUtils.obtainDensity(resources);
	slopShiftSize = (int) (6f * density);
	lastItemLimit = (int) (72f * density);
	if (fullScreenLayoutEnabled) {
		if (C.API_LOLLIPOP) {
			int statusBarColor = window.getStatusBarColor() | Color.BLACK;
			int navigationBarColor = window.getNavigationBarColor() | Color.BLACK;
			window.setStatusBarColor(Color.TRANSPARENT);
			window.setNavigationBarColor(Color.TRANSPARENT);
			contentForeground = new LollipopContentForeground(statusBarColor, navigationBarColor);
			statusBarContentForeground = new LollipopStatusBarForeground(statusBarColor);
			statusBarDrawerForeground = new LollipopDrawerForeground();
		} else {
			contentForeground = new KitKatContentForeground();
			statusBarContentForeground = null;
			statusBarDrawerForeground = null;
		}
		window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
				View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
	} else {
		contentForeground = null;
		statusBarContentForeground = null;
		statusBarDrawerForeground = null;
		if (enabled) {
			window.requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
		}
	}
	readConfiguration(resources.getConfiguration());
}
 
源代码9 项目: Android-utils   文件: BarUtils.java
/**
 * Return the color of navigation bar.
 *
 * @param window The window.
 * @return the color of navigation bar
 */
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static int getNavBarColor(@NonNull final Window window) {
    return window.getNavigationBarColor();
}
 
源代码10 项目: AndroidUtilCode   文件: BarUtils.java
/**
 * Return the color of navigation bar.
 *
 * @param window The window.
 * @return the color of navigation bar
 */
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static int getNavBarColor(@NonNull final Window window) {
    return window.getNavigationBarColor();
}