API级别21或更高级别的状态栏颜色根据我的要求而变化,但是如何更改API级别21以下的颜色。
以下是两个API的屏幕截图
API级别21:

API等级19:

colors.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FFFFFF</color>
<item name="b" type="color">#FF33B5E5</item>
<item name="p" type="color">#FFAA66CC</item>
<item name="g" type="color">#FF99CC00</item>
<item name="o" type="color">#FFFFBB33</item>
</resources>
Run Code Online (Sandbox Code Playgroud)
Style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBarOverlay">false</item>
<item name="windowNoTitle">true</item>
<item name="windowActionBar">false</item>
</style>
<style name="AppTheme.NoActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
<item name="tabSelectedTextColor">@color/colorAccent</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" /> …Run Code Online (Sandbox Code Playgroud) 我想分享GCM通知项目.共享按钮响应点击事件,项目也被共享.这里唯一的问题是,通知托盘下方有Intent选择器对话框.用户必须手动关闭状态栏,然后选择要共享的应用程序.我想以编程方式关闭状态栏,以便当用户单击共享时,它会直接向他显示选择应用程序的对话框.
我发现该status bar服务可用于打开/关闭服务.但它仅限于系统应用程序.
private void closeNotificationTray() {
Object service = mContext.getSystemService(Context.STATUS_BAR_SERVICE);
Method collapse;
try {
Class<?> statusBarMngr = Class.forName("android.app.StatusBarManager");
if (Build.VERSION.SDK_INT >= 17)
collapse = statusBarMngr.getMethod("collapsePanels");
else
collapse = statusBarMngr.getMethod("collapse");
collapse.invoke(service);
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
我用了上面的代码.但我得到"STATUS_BAR_SERVICE无法重新发送"错误.当我在清单中添加以下权限时:
<uses-permission
android:name="android.permission.STATUS_BAR" />
Run Code Online (Sandbox Code Playgroud)
我得到了,只允许系统apps.It不允许我在我的应用程序中使用.有没有办法使用status bar服务或任何其他替代方案?
更新:
我用2行代码解决了上述问题.无需调用STATUS_BAR_SERVICE.
Intent it = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
mContext.sendBroadcast(it);
Run Code Online (Sandbox Code Playgroud)
调用此意图将自动关闭通知
我想制作一个覆盖整个屏幕的覆盖屏幕,包括状态栏和导航栏。
我花了几个小时的谷歌搜索/研究仍然没有运气。
这是我的代码:
MainActivity.java(启动器):
package com.blogspot.diannaoxiaobai.myapplication;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startActivity(new Intent(this, Main2Activity.class));
}
}
Run Code Online (Sandbox Code Playgroud)
活动_main.xml :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.blogspot.diannaoxiaobai.myapplication.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
Main2Activity.java(由MainActivity启动):
package com.blogspot.diannaoxiaobai.myapplication;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
public class Main2Activity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) …Run Code Online (Sandbox Code Playgroud) android overlay android-theme android-overlay android-statusbar
基于以下代码片段,我想知道如何隐藏软键(状态栏和导航栏)并在整个应用程序会话中保持沉浸模式,即使显示 AlertDialog 也是如此:
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
AlertDialog.Builder dialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dialog = new AlertDialog.Builder(this);
findViewById(R.id.button).setOnClickListener(this);
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.button:
dialog.setTitle("Title");
dialog.setMessage("Message");
dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
// Dismisses dialog.
}
}).create().show(); …Run Code Online (Sandbox Code Playgroud) android focus android-alertdialog android-statusbar android-navigation-bar
我想知道如何更改android Oreo中的通知栏小图标(API 26).它在通知栏中显示圆形白色图标.我该怎么改变它?清单文件默认通知图标设置如下.
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_status" />
Run Code Online (Sandbox Code Playgroud)
见下图
android android-notifications android-notification-bar android-statusbar
我想操纵状态栏(ex.color)但在后台.我正在使用前台服务来执行此操作.因此,没有窗口,因为它在后台发生,特别是没有活动.但是,功能
public abstract void setStatusBarColor (int color)
Run Code Online (Sandbox Code Playgroud)
由抽象类Window调用:https://developer.android.com/reference/android/view/Window.html
所以因为它是抽象的我无法启动它而且我不能使用getWindow()因为我没有实现一个活动类.以下答案使用Activity.还有其他方法可以实现吗? 如何更改android中的状态栏颜色
android statusbar android-windowmanager android-statusbar android-window
我在应用程序中隐藏状态和导航栏时遇到一些问题。
假设:
解决方案如
window.apply {
clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR
} else {
decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
}
statusBarColor = Color.TRANSPARENT
}
Run Code Online (Sandbox Code Playgroud)
无法正常工作
我目前可以使用基本活动中的以下内容将状态栏文本颜色从浅色更新为深色:
private fun toggleStatusBarTextColor(light: Boolean) {
// clear any existing flags
window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_VISIBLE;
if(light) {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN)
} else {
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR)
}
}
Run Code Online (Sandbox Code Playgroud)
systemUiVisibility 现在在 API 30 上显示已弃用,尽管已弃用的方法暂时仍将起作用,但我更愿意用更新的方法替换它们来实现此目的。我读到我们现在应该使用 WindowInsetsController 函数,但尚不清楚如何从文档中完成此操作。有人能指出我正确的方向吗?
如何使状态和选项栏(底部)透明?
我尝试了很多想法,但它仍然是黑色和白色文本
这是我已经实现的代码:
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
...
SystemChrome.setSystemUIOverlayStyle(SystemUiOverlayStyle(
systemStatusBarContrastEnforced: true,
statusBarColor: Colors.transparent,
systemNavigationBarColor: Colors.transparent,
systemNavigationBarDividerColor: Colors.transparent,
systemNavigationBarIconBrightness: Brightness.light,
statusBarIconBrightness: Brightness.light));
SystemChrome.setEnabledSystemUIMode(SystemUiMode.edgeToEdge,
overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]);
...
runApp(...)
Run Code Online (Sandbox Code Playgroud)
在我的 Material 应用程序中:
return MaterialApp.router(
theme: ThemeData(
appBarTheme: AppBarTheme(
//systemOverlayStyle: SystemUiOverlayStyle.light,
backgroundColor: Colors.transparent),
),
color: Colors.transparent,
...
Run Code Online (Sandbox Code Playgroud)
我知道 AppBar 和状态栏不一样(只是想包含它)。预先非常感谢。
更新:
我试图删除安全区域,它显然与状态栏和导航栏发生冲突。结果是这样的:
现在它仍然不是真正透明,而且底部也很混乱。有任何想法吗?
我正在关注developer.google的主题教程。我正在尝试将应用程序迁移到 Mat。3、修改状态栏的颜色以与背景颜色相匹配。
添加android:statusBarColor和后android:windowLightStatusBar,没有任何变化。
我注意到在应用程序加载的第一时刻,状态栏确实符合我的预期,但过了一会儿就变得错误了。
之前: https: //i.stack.imgur.com/i43cL.png
之后: https: //i.stack.imgur.com/kMwaP.png
我尝试过的:
// res/values/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Superheroes" parent="android:Theme.Material.Light.NoActionBar">
<item name="android:statusBarColor">@color/background_light</item>
<item name="android:windowLightStatusBar">true</item>
<item name="android:windowBackground">@color/background_light</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)
// res/values-night/themes.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="Theme.Superheroes" parent="android:Theme.Material.NoActionBar">
<item name="android:statusBarColor">@color/background_dark</item>
<item name="android:windowLightStatusBar">false</item>
<item name="android:windowBackground">@color/background_dark</item>
</style>
</resources>
Run Code Online (Sandbox Code Playgroud)