Android 带浅色应用程序主题的深色工具栏
我知道以前有人问过这个问题,它对我很有用,但在升级到App Compat版本23后,工具栏现在有了黑色文本颜色(我希望它是白色的),我什么也没有改变 Toolbar.xml:Android 带浅色应用程序主题的深色工具栏,android,android-support-library,android-appcompat,Android,Android Support Library,Android Appcompat,我知道以前有人问过这个问题,它对我很有用,但在升级到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="htt
<?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>
改变
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
到
Android Studio引入默认项目模板的新支持库(AppCompat)没有在旧版本的Android中插入重要属性来设置工具栏的样式
这就是我的工作原理(我正在使用带有工具栏和TabLayout的AppBarLayout,如图所示):
app:tabGravity=“填充”
应用程序:tabMode=“固定”/>
我没有研究过这里到底发生了什么,但是旧的Android版本确实需要在每个元素中设置主题
希望它能帮助那些试图找到解决“灯光工具栏”主题中黑色文本的方法的人 好的,谢谢,伙计,成功了!但你能解释一下我为什么要改变这一点吗。知道它曾经在AppCompat修订版中工作22@rashad.z这是一个内部变化。以前您使用的
local:theme
是正确的,但是现在(我认为是从v23版本开始)支持类是从android:theme
属性读取的,因此如果您使用本地名称空间,它将没有任何效果。
Toolbar Toolbar = (Toolbar) AppCompatActivity.findViewById(R.id.toolbar);
AppCompatActivity.setSupportActionBar(Toolbar);
ActionBar actionBar = ((AppCompatActivity)activity).getSupportActionBar();
actionBar.setTitle(title);
local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
<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>