gpt4 book ai didi

android - 如何管理状态栏颜色?

转载 作者:行者123 更新时间:2023-11-29 20:13:55 25 4
gpt4 key购买 nike

我是 android 初学者,我想创建与 Toolbar 相同的 status bar 并且当 DrawerLayout 打开时 statusBar 再次更改为与 DrawerLayout 相同,如何解决此问题。我已经在样式中设置了 parent="Theme.AppCompat.Light.NoActionBar

<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="#ed9797"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/DrawerLayout">

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?android:attr/actionBarSize"
android:background="#e62e2e"
android:minHeight="?attr/actionBarSize"
app:contentInsetEnd="0dp"
app:contentInsetStart="0dp">
</android.support.v7.widget.Toolbar>
</RelativeLayout>

<FrameLayout
android:id="@+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />


<ListView
android:background="#46dfcd"
android:id="@+id/leftDrawer"
android:layout_width="250dp"
android:layout_height="match_parent"
android:text="Drawer page"
android:layout_gravity="start"/>

最佳答案

要更改状态栏颜色,请使用 setStatusBarColor(int color)。

工作代码 fragment :

Window window = activity.getWindow();
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.setStatusBarColor(activity.getResources().getColor(R.color.example_color));

关于android - 如何管理状态栏颜色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34355071/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com