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

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

源代码1 项目: PlayTogether   文件: ChatHomeActivity.java
@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;
}
 
源代码2 项目: DeviceInfo   文件: OSFragment.java
@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;
    }
 
源代码3 项目: 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);
        }
    }
}
 
源代码4 项目: Girls   文件: ImageViewPagerActivity.java
@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();
}
 
源代码5 项目: FamilyChat   文件: ScreenUtils.java
/**
 * 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);//切换导航栏颜色
    }
}
 
源代码6 项目: ShaderEditor   文件: SystemBarMetrics.java
@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;
}
 
源代码7 项目: V2EX   文件: StatusBarUtil.java
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);
}
 
源代码8 项目: Sofia   文件: Utils.java
/**
 * 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);
    }
}
 
源代码9 项目: Cornowser   文件: BarColors.java
/**
 * 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));
    }
}
 
源代码10 项目: PlayTogether   文件: BaseActivity.java
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);
    }
}
 
@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);
}
 
源代码12 项目: ToDoList   文件: RegisterActivity.java
/**
 * 设置状态栏透明
 */
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);
    }
}
 
源代码13 项目: ToDoList   文件: EditTodoActivity.java
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);
    }
}
 
源代码14 项目: ToDoList   文件: NewClockActivity.java
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);
    }
}
 
源代码15 项目: Dashchan   文件: GalleryActivity.java
@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);
	}
}
 
源代码16 项目: QuickLyric   文件: MainActivity.java
@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);
    }
}
 
源代码17 项目: ToDoList   文件: LoginActivity.java
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);
    }
}
 
源代码18 项目: simple-keyboard   文件: LatinIME.java
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);
    }
}
 
源代码19 项目: 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());
}
 
源代码20 项目: Android-utils   文件: BarUtils.java
/**
 * 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);
}