gpt4 book ai didi

android - 通过 theme 设置 StatusBar 颜色。

转载 作者:行者123 更新时间:2023-11-29 15:05:02 24 4
gpt4 key购买 nike

我打算通过 styles.xml 更改状态栏颜色,但无法设置状态栏颜色。我不想通过编码设置状态栏的颜色,我只想通过theme/style

Activity.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="eazitouk.eazitoclient.mainclasses.TestActivity">

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

</android.support.design.widget.AppBarLayout>

<include layout="@layout/content_test" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

list .xml

<application
android:name="eazitouk.eazitoclient.miscs.AppController"
android:icon="@drawable/ic_launchicon"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".TestActivity"
android:label="@string/title_activity_test"
android:theme="@style/AppTheme1">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

颜色.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

<color name="ColorPrimary">#df4a43</color>
<color name="ColorPrimaryDark">#c8423c</color>

<color name="ColorPrimary1">#FFCF3B</color>
<color name="ColorPrimaryLight">#F3A2A0</color>
<color name="ColorPrimaryLightShade">#e56e66</color>

</resources>

样式.xml

<resources>

<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
</style>

<style name="AppTheme1" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/ColorPrimary</item>
<item name="colorPrimaryDark">@color/ColorPrimaryDark</item>
<item name="android:textColorSecondary">@color/accentcolor</item>-->
</style>
</resources>

这是我的 style.xml,AppTheme 应用于应用程序,AppTheme1 应用于我的 Activity ,但无法设置状态栏颜色

最佳答案

我已经测试了你的代码。现在更改为您的 style 有问题。所以按照我的方式获取输出。

Android list .xml。

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:largeHeap="true"
android:screenOrientation="portrait"
android:theme="@style/AppTheme">

<activity
android:name=".TestActivity"
android:label="@string/title_activity_test"
android:theme="@style/AppTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

<color name="primaryColor">#EF6C00</color>
<color name="primaryColorDark">#E65100</color>
<color name="accentcolor">#0072BA</color>

</resources>

styles.xml

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/primaryColor</item>
<item name="colorPrimaryDark">@color/primaryColorDark</item>
<item name="colorAccent">@color/accentcolor</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />


</resources>

styles.xml(v21)

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>

</resources>

最终输出:

enter image description here

还有一点请记住,您已经设置了 targetSdkVersion 23

关于android - 通过 theme 设置 StatusBar 颜色。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38279276/

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