【问题标题】:Android toolbar white vs blackAndroid工具栏白色与黑色
【发布时间】:2016-03-08 10:44:02
【问题描述】:
<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="wrap_content"
    android:background="@color/purple2"
    android:minHeight="56dp"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:titleTextAppearance="@style/ToolbarTitle" />

在我的 nexus 6 上,后退按钮是白色的,3 点菜单是白色的,标题是白色的。在我运行的模拟器上,API 级别 14 标题为白色,但后退箭头和点菜单为黑色。怎么会?

【问题讨论】:

  • 这与 CSS 有什么关系?对于这些 API 级别,您可能有不同的主题。
  • 您使用的是哪个设计支持库?哪个版本?
  • 编译'com.android.support:appcompat-v7:23.2.0' 编译'com.android.support:design:23.2.0'

标签: android


【解决方案1】:

我可以通过检查下面的解决方案来解决类似的问题。我发布了同样的解决方案HERE

我发现 AppCompat 主题正在使用以下资源作为溢出按钮(3 个点):abc_ic_menu_overflow_material.xml

此资源的内容是:

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="24dp"
        android:height="24dp"
        android:viewportWidth="24.0"
        android:viewportHeight="24.0"
        android:tint="?attr/colorControlNormal">
    ...
</vector>

所以,如你所见,它使用了 colorControlNormal 和 vectorDrawables

如何解决

根据库 V23.2.0 发行说明 (LINK HERE),我们必须更新 build.gradle 以添加对 Vector 的支持:

build.gradle

将以下行添加到您的构建 gradle

Gradle 2.0(我没有测试):

android {  
    defaultConfig {  
        vectorDrawables.useSupportLibrary = true  
    }  
}  

Gradle 1.5(我正在使用这个.. 它有效):

android {  
    defaultConfig {  
        generatedDensities = []  
    }  

    aaptOptions {  
        additionalParameters "--no-version-vectors"  
    }  
}  

修复您的主题

也许,这一步是不需要的(因为也许,你的父主题已经将颜色设置为白色)。

但是如果这些按钮仍然是黑色的,您必须将 ColorControlNormal 添加到您的主题中:

工具栏布局

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    ...
    android:theme="@style/MyToolBarStyle"
    ...  />

styles.xml

<style name="MyToolBarStyle" parent="ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="colorControlNormal">@color/white</item>
</styel>

这就是我解决问题的方法。

【讨论】:

    【解决方案2】:
      defaultConfig {
        applicationId "com.myapp.app"
        minSdkVersion 10
        targetSdkVersion 22
        multiDexEnabled true
        versionCode 25
        versionName "1.24"
        generatedDensities = []
    }
    // This is handled for you by the 2.0+ Gradle Plugin
    // This is handled for you by the 2.0+ Gradle Plugin
    aaptOptions {
        additionalParameters "--no-version-vectors"
    }
    

    这解决了我的 2 台设备的情况,不确定现在是否所有设备都相同。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多