gpt4 book ai didi

java - 无法更改工具栏文本颜色

转载 作者:行者123 更新时间:2023-12-01 09:54:14 24 4
gpt4 key购买 nike

我想确保涵盖与此问题相关的所有版本,但我想更改工具栏的文本颜色。目前它是黑色的,我希望将其更改为白色。我知道 API < 21 和 API 23 有不同的处理方式。

这是我的主题:

<style name="AppTheme.NoActionBar" parent="Theme.AppCompat.Light">
<item name="android:radioButtonStyle">@style/Theme.AppCompat.DayNight</item>
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:textColor">@color/black</item>
<item name="android:textColorPrimary">@color/black</item>
<item name="android:textColorSecondary">@color/white</item>

<item name="android:actionBarStyle">@style/MyTheme.ActionBarStyle</item>
<item name="colorControlActivated">@android:color/holo_red_light</item>
<item name="colorControlNormal">@android:color/black</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

</style>


<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
<item name="color">@android:color/white</item>
</style>

<style name="MyTheme.ActionBarStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:titleTextStyle">@style/MyTheme.ActionBar.TitleTextStyle</item>
</style>

<style name="MyTheme.ActionBar.TitleTextStyle" parent="@style/TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="colorAccent">@color/white</item>
<item name="android:textColorPrimary">@color/white</item>
</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_test"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:minHeight="?attr/actionBarSize"
android:theme="@style/MyTheme"
android:background="@color/actionRed">

Activity XML:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

<include
android:id="@+id/tool_bar"
layout="@layout/toolbar_one" />

<android.support.v4.view.ViewPager
android:id="@+id/home_polls_viewpager_fragment_container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

</android.support.v4.view.ViewPager>

</LinearLayout>

最佳答案

For changing toolbar text color, you can use this theme

<style name="HomeTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/black</item>
<item name="colorPrimaryDark">@color/black</item>
<item name="android:windowBackground">@color/bg</item>
<item name="android:textColorSecondary">@color/white</item>
<item name="android:textColorPrimary">@color/white</item>
<item name="colorAccent">@color/white</item>
<item name="android:activatedBackgroundIndicator">@drawable/drawer_list_selector</item>
</style>

and for toolbar, you can use
<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:titleTextColor="@color/white"
app:popupTheme="@style/AppTheme.PopupOverlay" >

If still it not work, you can change toolbar color at programing time by
toolbar.setTitleColor(getResources.getColor(R.color.white)

Even still it not work, you can customize toolbar as

<android.support.v7.widget.Toolbar
android:id="@+id/main_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" >


<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/accept_order"
android:layout_gravity="center"
android:textSize="@dimen/twenty"
android:textColor="@color/white"
android:id="@+id/toolbar_title" />
</android.support.v7.widget.Toolbar>

关于java - 无法更改工具栏文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37365643/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com