gpt4 book ai didi

未应用 Android 自定义工具栏主题

转载 作者:行者123 更新时间:2023-12-05 07:53:10 27 4
gpt4 key购买 nike

我有一个使用自定义工具栏样式的应用程序。以前,它可以正确应用主题,但在最近更新 Android Studio 后,它已停止正常工作。

theme.xml 定义如下:

<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="OurTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">

<item name="android:actionBarStyle">@style/MyActionBar</item>
<item name="android:buttonStyle">@style/ButtonAppTheme</item>
<item name="android:imageButtonStyle">@style/ImageButtonAppTheme</item>
<item name="android:listSeparatorTextViewStyle">@style/BlueListSeparatorTextViewStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>

<!-- colorPrimary is used for the default action bar background -->
<item name="colorPrimary">@color/action_bar_color</item>

<!-- colorPrimaryDark is used for the status bar -->
<!--<item name="colorPrimaryDark">@color/my_awesome_darker_color</item>-->

<!-- colorAccent is used as the default value for colorControlActivated
which is used to tint widgets -->
<item name="colorAccent">@color/btn_accent_color</item>
</style>

<!-- Application theme. -->
<style name="OurTheme" parent="OurTheme.Base">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="android:listSeparatorTextViewStyle">@style/BlueListSeparatorTextViewStyle</item>
<item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>


</resources>

我们的 styles.xml 包含:

<!-- ActionBar styles ThemeOverlay.AppCompat.ActionBar -->
<style name="MyActionBar" parent="Widget.AppCompat.ActionBar">
<item name="android:titleTextStyle">@style/MyActionBarTitleText</item>
</style>

<!-- ActionBar title text -->
<style name="MyActionBarTitleText" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
<item name="android:textColor">@color/actionbar_text</item>
</style>

actionbar_text 在我们的 colors.xml 中定义:

<color name="actionbar_text">#ffffffff</color>

最后,我们的自定义工具栏布局:

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

以前,这是有效的,我们的应用程序在其自定义工具栏中有白色文本。它现在在应用程序中的所有位置都默认为黑色,我发现可以更改工具栏标题文本颜色的唯一方法(除了在代码中执行)是将工具栏布局更改为:

<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="?attr/actionBarSize"
app:titleTextAppearance="@style/MyActionBarTitleText"
app:theme="@style/ThemeOverlay.AppCompat.Dark" />

请注意,现在我特别告诉操作栏使用 MyActionBarTitleText 样式。

我还尝试通过将“app:theme”更改为:专门告诉它在这里也使用自定义主题:

app:theme="@style/MyActionBar"

但这并没有帮助。

我怕是手足无措了。我知道基本主题可以工作,因为我可以更改背景颜色,但是使用 actionBarStyle 项目根本无法工作。

这也影响了我们的一些自定义按钮布局的文本布局和理由,我不明白为什么它停止工作。有人有什么建议吗?

最佳答案

虽然很晚了,但还是要回答。

为您的工具栏创建自定义主题并设置android:background

<style name="ToolbarStyle" parent="Widget.AppCompat.Toolbar">
<item name="android:background">@color/blue</item> // change your color here and add other attributes
</style>

现在将这个主题以 XML 格式应用到您的工具栏,例如:

style="@style/ToolbarStyle"

关于未应用 Android 自定义工具栏主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32949747/

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