- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想在我的应用程序中将状态栏设置为白色背景和黑色文本(和黑色图标)。我发现一些应用程序可以做到这一点。但是从谷歌搜索,我找不到任何解决方案来做到这一点。关于如何设置状态栏的颜色有很多解决方案。也像 SystemBarTint ,它只能设置背景,但不能设置整个状态栏的样式(白色背景和黑色文本)。
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.apache.cordova.statusbar;
import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaArgs;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView;
import org.apache.cordova.LOG;
import org.apache.cordova.PluginResult;
import org.json.JSONException;
import java.util.Arrays;
public class StatusBar extends CordovaPlugin {
private static final String TAG = "StatusBar";
/**
* Sets the context of the Command. This can then be used to do things like
* get file paths associated with the Activity.
*
* @param cordova The context of the main Activity.
* @param webView The CordovaWebView Cordova is running in.
*/
@Override
public void initialize(final CordovaInterface cordova, CordovaWebView webView) {
LOG.v(TAG, "StatusBar: initialization");
super.initialize(cordova, webView);
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially
// by the Cordova.
Window window = cordova.getActivity().getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
// Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
// Read 'StatusBarStyle' from config.xml, default is 'lightcontent'.
setStatusBarStyle(preferences.getString("StatusBarStyle", "lightcontent"));
}
});
}
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackContext The callback id used when calling back into JavaScript.
* @return True if the action was valid, false otherwise.
*/
@Override
public boolean execute(final String action, final CordovaArgs args, final CallbackContext callbackContext) throws JSONException {
LOG.v(TAG, "Executing action: " + action);
final Activity activity = this.cordova.getActivity();
final Window window = activity.getWindow();
if ("_ready".equals(action)) {
boolean statusBarVisible = (window.getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) == 0;
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, statusBarVisible));
return true;
}
if ("show".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// SYSTEM_UI_FLAG_FULLSCREEN is available since JellyBean, but we
// use KitKat here to be aligned with "Fullscreen" preference
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int uiOptions = window.getDecorView().getSystemUiVisibility();
uiOptions &= ~View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
uiOptions &= ~View.SYSTEM_UI_FLAG_FULLSCREEN;
window.getDecorView().setSystemUiVisibility(uiOptions);
}
// CB-11197 We still need to update LayoutParams to force status bar
// to be hidden when entering e.g. text fields
window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});
return true;
}
if ("hide".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
// SYSTEM_UI_FLAG_FULLSCREEN is available since JellyBean, but we
// use KitKat here to be aligned with "Fullscreen" preference
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
int uiOptions = window.getDecorView().getSystemUiVisibility()
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_FULLSCREEN;
window.getDecorView().setSystemUiVisibility(uiOptions);
}
// CB-11197 We still need to update LayoutParams to force status bar
// to be hidden when entering e.g. text fields
window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
});
return true;
}
if ("backgroundColorByHexString".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
setStatusBarBackgroundColor(args.getString(0));
} catch (JSONException ignore) {
LOG.e(TAG, "Invalid hexString argument, use f.i. '#777777'");
}
}
});
return true;
}
if ("overlaysWebView".equals(action)) {
if (Build.VERSION.SDK_INT >= 21) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
try {
setStatusBarTransparent(args.getBoolean(0));
} catch (JSONException ignore) {
LOG.e(TAG, "Invalid boolean argument");
}
}
});
return true;
}
else return args.getBoolean(0) == false;
}
if ("styleDefault".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("default");
}
});
return true;
}
if ("styleLightContent".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("lightcontent");
}
});
return true;
}
if ("styleBlackTranslucent".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("blacktranslucent");
}
});
return true;
}
if ("styleBlackOpaque".equals(action)) {
this.cordova.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
setStatusBarStyle("blackopaque");
}
});
return true;
}
return false;
}
private void setStatusBarBackgroundColor(final String colorPref) {
if (Build.VERSION.SDK_INT >= 21) {
if (colorPref != null && !colorPref.isEmpty()) {
final Window window = cordova.getActivity().getWindow();
// Method and constants not available on all SDKs but we want to be able to compile this code with any SDK
window.clearFlags(0x04000000); // SDK 19: WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.addFlags(0x80000000); // SDK 21: WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
try {
// Using reflection makes sure any 5.0+ device will work without having to compile with SDK level 21
window.getClass().getMethod("setStatusBarColor", int.class).invoke(window, Color.parseColor(colorPref));
} catch (IllegalArgumentException ignore) {
LOG.e(TAG, "Invalid hexString argument, use f.i. '#999999'");
} catch (Exception ignore) {
// this should not happen, only in case Android removes this method in a version > 21
LOG.w(TAG, "Method window.setStatusBarColor not found for SDK level " + Build.VERSION.SDK_INT);
}
}
}
}
private void setStatusBarTransparent(final boolean transparent) {
if (Build.VERSION.SDK_INT >= 21) {
final Window window = cordova.getActivity().getWindow();
if (transparent) {
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
window.setStatusBarColor(Color.TRANSPARENT);
}
else {
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_VISIBLE);
}
}
}
private void setStatusBarStyle(final String style) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
if (style != null && !style.isEmpty()) {
View decorView = cordova.getActivity().getWindow().getDecorView();
int uiOptions = decorView.getSystemUiVisibility();
String[] darkContentStyles = {
"default",
};
String[] lightContentStyles = {
"lightcontent",
"blacktranslucent",
"blackopaque",
};
if (Arrays.asList(darkContentStyles).contains(style.toLowerCase())) {
decorView.setSystemUiVisibility(uiOptions | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
return;
}
if (Arrays.asList(lightContentStyles).contains(style.toLowerCase())) {
decorView.setSystemUiVisibility(uiOptions & ~View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
return;
}
LOG.e(TAG, "Invalid style, must be either 'default', 'lightcontent' or the deprecated 'blacktranslucent' and 'blackopaque'");
}
}
}
}
How to set Status bar to white background and black text (black icon) in my app
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().setStatusBarColor(Color.TRANSPARENT);// SDK21
最佳答案
要将状态栏颜色设置为白色,您可以在 config.xml 中使用此首选项
<preference name="StatusBarBackgroundColor" value="#FFFFFF" />
要将文本和图标设置为黑色,您可以在 config.xml 中使用此首选项。但这只适用于 Android 6+,在以前的版本中无法设置图标/文本颜色。
<preference name="StatusBarStyle" value="default" />
关于java - 如何在我的 Cordova 应用程序中将状态栏设置为白色背景和黑色文本(黑色图标),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48699353/
我刚刚创建了一个带有几个表 Controller 和一个 View Controller 的 Storyboard。 一切正常,直到我的应用程序推送 View Controller :它显示为全黑。
我尝试通过添加一个名为“铀”的新元素来修改我的世界。因此,我在主包中创建了“Trauma.java”类以及下面列出的其他一些类。所有包和类: Package Explorer Trauma.java
我一直在学习如何使用 UICollection View 。我制作了一个新的 UICollectionView Controller ,并将 collectionview 单元格标识为 main.st
我想加一个超细的黑边 在这个环的边界上方和下方。 http://jsfiddle.net/PUBqA/5/ 目标是让这个戒指容易看 在白色背景上。 唯一的方法就是添加一些薄的 环外环内黑色边框。 这是
假设我有以下 python 文件 exclude_from_black.py在我的项目的根目录中: print('I want single quotes') 我试图从黑色重新格式化中排除此文件,但以
我的 Canvas 有问题。比方说,1/10 的时候我在 chrome 上有黑色方 block 而不是我的图像。我的代码如下,我该如何修改它以避免这种黑色显示? var canvas = docu
我正在尝试使用图案作为 SKScene 的背景颜色: override func didMoveToView(view: SKView) { let backgroundImage:
我正在尝试浏览一些 Collection View Swift 教程,但它们总是显示为空白/黑色页面,就好像我没有设置初始 View Controller 一样。不过,我只使用了 1 个 UIColl
我有一个标签栏应用程序。 标签栏中只有 2 个选项卡。第一个选项卡是 NavigationController,第二个选项卡是 TableViewController。第二个工作完美,但第一个则不然。
我正在通过串行端口(ttyO2)连接 BBB 和一组 arduino。我有一个数组要从 BBB 发送到一组 arduino。我需要让 BBB 发送请求并等待其中一个 arduino 的回复,但如果在一
附上图片。我能够摆脱边界上的背景区域,但图像中的背景区域仍然存在。有没有什么方法可以消除图像中的小背景区域。谢谢。 最佳答案 这个问题有一个简单的解决方法,基本思想是在 RGB 颜色空间中分割图像以过
我以前从未做过图像处理。 我现在需要检查来自相机的许多 jpeg 图像,以丢弃那些非常暗(几乎是黑色)的图像。 是否有我可以使用的免费库 (.NET)?谢谢。 最佳答案 Aforge是一个很棒的图像处
这个问题在这里已经有了答案: Background ListView becomes black when scrolling (12 个答案) 关闭 9 年前。 这是我第一次访问这个网站。我会请你
我在 iOS 上更改启动屏幕的背景颜色时遇到问题。当我第一次打开应用程序时,它会在黑色 viewcontroller 出现之前加载一个白页。如何将白色启动屏幕更改为黑色? 下面是我的应用程序的一般启动
我想检测字体的样式(粗体、粗体、黑色)。但我只能检测字体是否为粗体。 BOOL isBold = (font.fontDescriptor.symbolicTraits & UIFontDescrip
我正在尝试解决一个软件错误,在该错误中,我们认为某个应用可能不会在每次调用时都启动。为了对此进行测试,我创建了一系列计划任务来启动应用程序、截取屏幕截图,然后关闭应用程序。这些任务都是通过 .bat
完全被难住了。我已经遍地查看并实现了我能找到的每一个解决方案。我似乎无法让导航栏变得透明。 当尝试设置背景颜色时,我只在顶部看到一个黑条。就像我尝试设置背景图像一样。我已经尝试了所有这些以及所有这些变
我创建了一个 TextView ,如果文本太长,它将使其可滚动。但是,如果您单击它或将手指放在上面,它会像被单击一样变成黑色。有谁知道使它不能点击但仍然能够滚动的代码?谢谢! 在我的 xml 中定义其
我正在尝试将 DS1307 RTC 集成到 beaglebone black 上,其中我正在使用 rootfs 构建自定义内核,我使用了 beagle P9.17 和 P9.18 的 SCL 和 SD
线性渐变适用于图像,但文本不会出现在图像前景上。此外,渐变不应该出现在文本上。我哪里做错了? 任何帮助都感激不尽。 .glimage { display: flex; justify-cont
我是一名优秀的程序员,十分优秀!