温馨提示:本文翻译自stackoverflow.com,查看原文请点击:其他 - Dark theme android app
android themes android-theme

其他 - 黑暗主题安卓应用

发布于 2020-03-29 21:37:44

我正在尝试在OnePlus设备上创建类似于OxygenOS中的主题。

在此处输入图片说明

我将窗口背景更改为黑色,但问题是操作栏没有变为纯黑色。

<style name="DarkTheme" parent="Theme.AppCompact">
    <item name="android:colorPrimary">@color/black</item>
    <item name="android:colorPrimaryDark">@color/black</item>
    <item name="android:textColorPrimary">@color/white</item>
    <item name="android:colorAccent">@color/white</item>
    <item name="android:color">@color/white</item>
    <item name="android:windowBackground">@color/black</item>
    <item name="android:navigationBarColor">@color/black</item>
    <item name="android:actionBarStyle">@color/black</item>
</style>

查看更多

提问者
Mark Ben
被浏览
24
Evin1_ 2016-01-23 08:46

将这些值替换为colors.xml

<color name="colorPrimary">#101010</color>
<color name="colorPrimaryDark">#000000</color>

这足以更改工具栏的颜色。


如果您不想更改整个应用的原色(看来这是您最初尝试做的事情),请尝试通过以下方法创建新的工具栏:

将此添加到您的应用程序的build.gradle

compile 'com.android.support:design:23.1.1'

将此添加到您的主布局(activity_main.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="mx.evin.apps.startingtemplate.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/a_main_toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/black"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

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

设置您的样式(styles.xml):

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
</style>

并设置新的工具栏(MainActivity.java)。

Toolbar toolbar = (Toolbar) findViewById(R.id.a_main_toolbar);
setSupportActionBar(toolbar);