下面列出了android.view.Window#getStatusBarColor ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.conversation_context, menu);
mode.setTitle("1");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
statusBarColor = window.getStatusBarColor();
window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
}
setCorrectMenuVisibility(menu);
AdaptiveActionsToolbar.adjustMenuActions(menu, 10, requireActivity().getWindow().getDecorView().getMeasuredWidth());
listener.onMessageActionToolbarOpened();
return true;
}
public static int getStatusBarColor(final Window window) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return window.getStatusBarColor();
} else {
ViewGroup decorViewGroup = (ViewGroup) window.getDecorView();
View statusBarView = decorViewGroup.findViewWithTag("custom_status_bar_tag");
if (statusBarView != null) {
Drawable drawable = statusBarView.getBackground();
if (drawable instanceof ColorDrawable) {
ColorDrawable colorDrawable = (ColorDrawable) drawable;
return colorDrawable.getColor();
}
}
}
return Color.BLACK;
}
@Nullable
@Override
public View onCreateView(
LayoutInflater layoutInflater, @Nullable ViewGroup viewGroup, @Nullable Bundle bundle) {
this.wrappedContext = new ContextThemeWrapper(getContext(), getShapeTheme());
LayoutInflater layoutInflaterWithThemedContext =
layoutInflater.cloneInContext(wrappedContext);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
statusBarColor = window.getStatusBarColor();
final TypedValue value = new TypedValue();
wrappedContext
.getTheme()
.resolveAttribute(R.attr.colorPrimaryDark, value, true);
window.setStatusBarColor(value.data);
}
return super.onCreateView(layoutInflaterWithThemedContext, viewGroup, bundle);
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.conversation_context, menu);
mode.setTitle("1");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
statusBarColor = window.getStatusBarColor();
window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
}
setCorrectMenuVisibility(menu);
return true;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.media_overview_context, menu);
mode.setTitle(getActionModeTitle());
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = requireActivity().getWindow();
originalStatusBarColor = window.getStatusBarColor();
window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
}
return true;
}
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;
}
private void tintStatusBar(float scrollOffset) {
int statusBarColor = toolbar.getResources().getColor(R.color.belvedere_image_stream_status_bar_color);
int colorPrimaryDark = Utils.getThemeColor(toolbar.getContext(), R.attr.colorPrimaryDark);
boolean fullyExpanded = scrollOffset == 1.f;
final Window window = activity.getWindow();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
if(fullyExpanded) {
if (window.getStatusBarColor() == colorPrimaryDark) {
final ValueAnimator animation = ValueAnimator.ofObject(new ArgbEvaluator(), colorPrimaryDark, statusBarColor);
animation.setDuration(100);
animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
public void onAnimationUpdate(ValueAnimator animator) {
window.setStatusBarColor((Integer) animation.getAnimatedValue());
}
});
animation.start();
}
} else {
window.setStatusBarColor(colorPrimaryDark);
}
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
View decor = window.getDecorView();
if(fullyExpanded) {
decor.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
} else {
decor.setSystemUiVisibility(0);
}
}
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.profile_context, menu);
mode.setTitle("1");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
originalStatusBarColor = window.getStatusBarColor();
window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
}
return true;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.profile_context, menu);
mode.setTitle("1");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
originalStatusBarColor = window.getStatusBarColor();
window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
}
return true;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
mode.getMenuInflater().inflate(R.menu.profile_context, menu);
mode.setTitle("1");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
originalStatusBarColor = window.getStatusBarColor();
window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
}
return true;
}
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.conversation_context, menu);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getActivity().getWindow();
statusBarColor = window.getStatusBarColor();
window.setStatusBarColor(getResources().getColor(R.color.action_mode_status_bar));
window.setNavigationBarColor(getResources().getColor(android.R.color.black));
}
setCorrectMenuVisibility(menu);
return true;
}
private void getStatusBatColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
statusBatColor = window.getStatusBarColor();
}
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public StatusBarObserver(Activity activity, TypedArray a, int attr) {
Window window = activity.getWindow();
mStatusBarColor = window.getStatusBarColor();
mStatusBarColorNight = a.getColor(attr,mStatusBarColorNight);
}
@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());
}