带有光应用主题的黑暗工具栏

时间:2015-10-13 11:43:41

标签: android android-support-library android-appcompat appcompat-v7-r23

我之前已经问过这个问题了,之前它对我有用,但在更新到App Compat第23版之后,工具栏现在有了黑色文字颜色(我希望它是白色的)我并没有改变一件事

Toolbar.xml:

select 
  c.name,
  avg(datediff(minute, t.start_time, t.end_time)) as avg_minutes
from customer c
left join times t on t.cust_id = c.id;
group by c.name;

styles.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    local:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    >

</android.support.v7.widget.Toolbar>

将工具栏设置为活动:

<style name="MyMaterialTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="android:windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="@attr/spinner_style">@style/spinner_style</item>
</style>

2 个答案:

答案 0 :(得分:1)

更改

local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

答案 1 :(得分:0)

Android Studio在默认项目模板中引入的新支持库(AppCompat)不会在较旧的Android版本中为样式工具栏插入重要属性。

这对我有用(我正在使用带有工具栏和TabLayout的AppBarLayout,如图所示):

<android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar"
        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"
            android:theme="@style/AppTheme.AppBarOverlay" <!-- Needed attribute -->
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:theme="@style/AppTheme.AppBarOverlay" <!-- Needed attribute -->
            app:tabGravity="fill"
            app:tabMode="fixed" />

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

我没有研究确切地知道这里发生了什么,但是较旧的Android版本确实需要在每个元素中设置主题。

希望它可以帮助那些试图找到光工具栏主题中黑色文本解决方案的人!

相关问题