Android支持工具栏样式
我试图用深色工具栏(操作栏)实现AppCompat的浅色主题,但是当动态添加工具栏或使用Android支持工具栏样式,android,android-appcompat,android-toolbar,Android,Android Appcompat,Android Toolbar,我试图用深色工具栏(操作栏)实现AppCompat的浅色主题,但是当动态添加工具栏或使用时,文本无法以正确的颜色显示(黑色而非白色)。默认的操作栏样式正确,但添加工具栏时却不正确 这是我的密码: toolbar.xml <android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.c
时,文本无法以正确的颜色显示(黑色而非白色)。默认的操作栏样式正确,但添加工具栏时却不正确
这是我的密码:
toolbar.xml
<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"
app:theme="@style/AppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:navigationContentDescription="@string/abc_action_bar_up_description"
android:background="?attr/colorPrimary"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="@string/action_settings"
/>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#ff299725</item>
<item name="colorPrimaryDark">#ff1d691b</item>
<item name="colorAccent">#ff5fb10b</item>
</style>
</resources>
<style name="Toolbar" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/xxx</item>
<item name="android:background">@color/xxx</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="color">@color/xxx</item>
<item name="gapBetweenBars">4dp</item>
</style>
<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="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/Toolbar"
/>
但是,我在预览和实时环境中得到了以下结果:
我尝试过不同版本的AppCompat(v.22.1、v.22.2、v.21.0.3)都复制了这个问题,我尝试过为textColor
添加额外的样式,结果是它将所有内容都设置为白色
有关于图例的帮助吗?
style.xml
<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"
app:theme="@style/AppTheme"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
app:navigationContentDescription="@string/abc_action_bar_up_description"
android:background="?attr/colorPrimary"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="@string/action_settings"
/>
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#ff299725</item>
<item name="colorPrimaryDark">#ff1d691b</item>
<item name="colorAccent">#ff5fb10b</item>
</style>
</resources>
<style name="Toolbar" parent="@style/ThemeOverlay.AppCompat.ActionBar">
<item name="android:textColorPrimary">@color/xxx</item>
<item name="android:background">@color/xxx</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>
<style name="DrawerArrowStyle" parent="@style/Widget.AppCompat.DrawerArrowToggle">
<item name="color">@color/xxx</item>
<item name="gapBetweenBars">4dp</item>
</style>
<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="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/Toolbar"
/>
在toolbar.xml中,删除
app:theme
属性,改为使用此属性:
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
此外,根据您实现工具栏的方式,您可能希望更改基本主题(在styles.xml中)以使用NoActionBar
变量,如下所示:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">