1

我知道这个问题已被问及之前,但它更新到App Compat修订23之前,但我的工具栏现在有一个黑色的文字颜色(我想它白色)和我没有改变一件事。黑暗的工具栏与光的应用程序主题

Toolbar.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> 

styles.xml

<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> 

设置工具栏活动:

Toolbar Toolbar = (Toolbar) AppCompatActivity.findViewById(R.id.toolbar); 
AppCompatActivity.setSupportActionBar(Toolbar); 
ActionBar actionBar = ((AppCompatActivity)activity).getSupportActionBar(); 
actionBar.setTitle(title); 

回答

1

变化

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

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

这个答案应该被接受。 –

+0

好的,谢谢你的工作!但你能解释为什么我必须改变这种情况吗?知道它曾经在AppCompat修订版22 –

+0

@ rashad.z中工作,这是一个内部变化。你之前使用'local:theme'是正确的,但是现在(从我认为的v23版本开始)从'android:theme'属性读取的支持类,所以如果你使用本地命名空间,它将不起作用。 – natario

0

新的支持库(程序兼容性)是Android Studio中默认的项目模板带来不较旧的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版本的真需要在每个元素的风格主题。

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