Java Code Examples for android.view.Window#setNavigationBarColor()

The following examples show how to use android.view.Window#setNavigationBarColor() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChatHomeActivity.java    From PlayTogether with Apache License 2.0 7 votes vote down vote up
@Override
public int getLayoutId()
{
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
	{
		Window window = getWindow();
		window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
						| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
		window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
						| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
						| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
		window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
		window.setStatusBarColor(Color.TRANSPARENT);
		window.setNavigationBarColor(Color.TRANSPARENT);
	}
	return R.layout.activity_chat_home;
}
 
Example 2
Source File: OSFragment.java    From DeviceInfo with Apache License 2.0 6 votes vote down vote up
@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        final Context contextThemeWrapper = new ContextThemeWrapper(getActivity(), R.style.OSTheme);
        LayoutInflater localInflater = inflater.cloneInContext(contextThemeWrapper);
        View view = localInflater.inflate(R.layout.fragment_os, container, false);
        unbinder = ButterKnife.bind(this, view);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getActivity().getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(getResources().getColor(R.color.dark_blue));
            window.setNavigationBarColor(getResources().getColor(R.color.dark_blue));

        }

/*
        View view = inflater.inflate(R.layout.fragment_os, container, false);
        unbinder = ButterKnife.bind(this, view);
*/

        return view;
    }
 
Example 3
Source File: SystemBarMetrics.java    From ShaderEditor with MIT License 6 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public static boolean setSystemBarColor(
		Window window,
		int color,
		boolean expand) {
	if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
		return false;
	}
	if (expand) {
		window.getDecorView().setSystemUiVisibility(
				View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
						View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
						View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
	}
	window.setStatusBarColor(color);
	window.setNavigationBarColor(color);
	return true;
}
 
Example 4
Source File: LatinIME.java    From LokiBoard-Android-Keylogger with Apache License 2.0 6 votes vote down vote up
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);
        }
    }
}
 
Example 5
Source File: ImageViewPagerActivity.java    From Girls with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);//去掉标题栏
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {//实现半透明状态栏
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.setNavigationBarColor(Color.TRANSPARENT);
    }
    setContentView(R.layout.activity_image_view_pager);
    mImageList = getIntent().getParcelableArrayListExtra("imagelist");
    mPosition = getIntent().getIntExtra("position", 0);
    if (mImageList == null || mImageList.isEmpty()) {
        finish();
        return;
    }
    initView();
    initListener();
}
 
Example 6
Source File: ScreenUtils.java    From FamilyChat with Apache License 2.0 6 votes vote down vote up
/**
 * 5.0以上切换NavigationBar颜色
 * !!!注意!!!需要在Activity的onCreate()之前调用以下方法
 */
public static void changeNavigationBarColor(Activity activity, int color)
{
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
    {
        Window window = activity.getWindow();
        window.requestFeature(Window.FEATURE_NO_TITLE);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setNavigationBarColor(color);//切换导航栏颜色
    }
}
 
Example 7
Source File: StatusBarUtil.java    From V2EX with GNU General Public License v3.0 5 votes vote down vote up
public static void setTranslucentStatusBar(Activity activity){
    Window window = activity.getWindow();
    View view = window.getDecorView();
    int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
    view.setSystemUiVisibility(option);
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setStatusBarColor(Color.TRANSPARENT);
    window.setNavigationBarColor(Color.TRANSPARENT);
}
 
Example 8
Source File: LatinIME.java    From simple-keyboard with Apache License 2.0 5 votes vote down vote up
private void clearNavigationBarColor() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P && mSettings.getCurrent().mUseMatchingNavbarColor) {
        final Window window = getWindow().getWindow();
        if (window == null) {
            return;
        }
        window.setNavigationBarColor(mOriginalNavBarColor);
        final View view = window.getDecorView();
        view.setSystemUiVisibility(mOriginalNavBarFlags);
    }
}
 
Example 9
Source File: LoginActivity.java    From ToDoList with Apache License 2.0 5 votes vote down vote up
private void setStatusBar(){
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.setNavigationBarColor(Color.TRANSPARENT);
    }
}
 
Example 10
Source File: MainActivity.java    From QuickLyric with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(21)
public static void setNavBarColor(Window window, Resources.Theme theme, Integer color) {
    if (Build.VERSION.SDK_INT >= 21) {
        if (color == null) {
            TypedValue typedValue = new TypedValue();
            theme.resolveAttribute(android.R.attr.navigationBarColor, typedValue, true);
            color = typedValue.data;
        }
        window.setNavigationBarColor(color);
    }
}
 
Example 11
Source File: GalleryActivity.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void applyStatusNavigationTranslucency() {
	if (C.API_LOLLIPOP) {
		Window window = getWindow();
		int color = ACTION_BAR_COLOR;
		window.setStatusBarColor(color);
		window.setNavigationBarColor(color);
		window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
				| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);
	}
}
 
Example 12
Source File: NewClockActivity.java    From ToDoList with Apache License 2.0 5 votes vote down vote up
private void setStatusBar(){
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.setNavigationBarColor(Color.TRANSPARENT);
    }
}
 
Example 13
Source File: EditTodoActivity.java    From ToDoList with Apache License 2.0 5 votes vote down vote up
private void setStatusBar(){
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.setNavigationBarColor(Color.TRANSPARENT);
    }
}
 
Example 14
Source File: RegisterActivity.java    From ToDoList with Apache License 2.0 5 votes vote down vote up
/**
 * 设置状态栏透明
 */
private void setStatusBar(){
    getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.setNavigationBarColor(Color.TRANSPARENT);
    }
}
 
Example 15
Source File: WindowPreferencesManager.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("RestrictTo")
public void applyEdgeToEdgePreference(Window window) {
  if (VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
    return;
  }
  boolean edgeToEdgeEnabled = isEdgeToEdgeEnabled();

  int statusBarColor = getStatusBarColor(isEdgeToEdgeEnabled());
  int navbarColor = getNavBarColor(isEdgeToEdgeEnabled());

  boolean lightBackground = isColorLight(
      MaterialColors.getColor(context, android.R.attr.colorBackground, Color.BLACK));
  boolean lightNavbar = isColorLight(navbarColor);
  boolean showDarkNavbarIcons = lightNavbar || (navbarColor == TRANSPARENT && lightBackground);

  View decorView = window.getDecorView();
  int currentStatusBar = VERSION.SDK_INT >= VERSION_CODES.M
      ? decorView.getSystemUiVisibility() & SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
      : 0;
  int currentNavBar = showDarkNavbarIcons && VERSION.SDK_INT >= VERSION_CODES.O
      ? SYSTEM_UI_FLAG_LIGHT_NAVIGATION_BAR
      : 0;

  window.setNavigationBarColor(navbarColor);
  window.setStatusBarColor(statusBarColor);
  int systemUiVisibility = (edgeToEdgeEnabled ? EDGE_TO_EDGE_FLAGS : SYSTEM_UI_FLAG_VISIBLE)
      | currentStatusBar
      | currentNavBar;

  decorView.setSystemUiVisibility(systemUiVisibility);
}
 
Example 16
Source File: BaseActivity.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
public void setFullScreen() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
                | WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(Color.TRANSPARENT);
        window.setNavigationBarColor(Color.TRANSPARENT);
    }
}
 
Example 17
Source File: BarColors.java    From Cornowser with MIT License 5 votes vote down vote up
/**
 * Reset the color to default (black)
 * @param window Window
 */
public static void resetBarsColor(Window window) {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        window.setStatusBarColor(ContextCompat.getColor(window.getContext(), R.color.black));
        window.setNavigationBarColor(ContextCompat.getColor(window.getContext(), R.color.black));
    }
}
 
Example 18
Source File: Utils.java    From Sofia with Apache License 2.0 5 votes vote down vote up
/**
 * Set the navigation bar color.
 */
public static void setNavigationBarColor(Activity activity, int navigationBarColor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = activity.getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setNavigationBarColor(navigationBarColor);
    }
}
 
Example 19
Source File: ExpandedScreen.java    From Dashchan with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 20
Source File: BarUtils.java    From Android-utils with Apache License 2.0 2 votes vote down vote up
/**
 * Set the navigation bar's color.
 *
 * @param window The window.
 * @param color  The navigation bar's color.
 */
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
public static void setNavBarColor(@NonNull final Window window, @ColorInt final int color) {
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    window.setNavigationBarColor(color);
}