【问题标题】:Strange behavior of styles (Themes) in AndroidAndroid中样式(主题)的奇怪行为
【发布时间】:2016-06-08 20:42:39
【问题描述】:

我为我的 Android 应用获得了这些样式:

<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">

    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:windowBackground">@color/background_new</item>
    <item name="android:textColorPrimary">@color/colorAccent</item>
    <item name="android:textColorHint">@color/colorAccentHint</item>

    <!-- Customize your theme here. -->
</style>

<style name="MyToolBar" parent="Widget.AppCompat.ActionBar">
    <!-- Support library compatibility -->
    <item name="android:textColorPrimary">@color/colorAccent</item>
    <item name="android:textColorSecondary">@color/colorAccent</item>
    <item name="colorControlNormal">@color/colorAccent</item>

</style>

<!-- Custom searchView may be used or not-->
<style name="SearchViewStyle" parent="Widget.AppCompat.SearchView">
    <!-- Gets rid of the search icon -->
    <item name="searchIcon">@null</item>
    <!-- Gets rid of the "underline" in the text -->
    <item name="queryBackground">@null</item>
    <!-- Gets rid of the search icon when the SearchView is expanded -->
    <item name="searchHintIcon">@null</item>
    <!-- The hint text that appears when the user has not typed anything -->
    <!--<item name="closeIcon">@null</item> -->
</style>

<style name="MyCustomTabLayout" parent="Widget.Design.TabLayout">
    <item name="tabTextAppearance">@style/MyCustomTabText</item>
</style>

<style name="MyCustomTabText" parent="TextAppearance.Design.Tab">
    <item name="android:textSize">12sp</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

<style name="NavDrawerTextStyle" parent="Base.TextAppearance.AppCompat">
    <item name="android:textSize">12sp</item>
</style>

<style name="MyCheckBox" parent="Theme.AppCompat.Light.NoActionBar">
    <item name="colorControlNormal">@color/colorPrimaryTransparent</item>
    <item name="colorControlActivated">@color/colorAccent</item>
</style>

<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
    <item name="colorAccent">@color/colorAccent</item>
    <item name="android:textColorPrimary">@color/colorAccent</item>
    <item name="android:background">@color/background1</item>
    <item name="android:buttonStyle">@style/MyApp.BorderlessButton</item>
</style>

<style name="MyApp.BorderlessButton" parent="@style/Widget.AppCompat.Button.Borderless">
    <item name="android:textSize">12sp</item>
</style>

<style name="MyRadioButton" parent="Theme.AppCompat.Light">
    <item name="colorControlNormal">@color/colorAccent</item>
    <item name="colorControlActivated">@color/colorAccent</item>
</style>

通常我在 NavigationDrawler 菜单项单击的 工具栏 上有透明背景。

但有时我的应用程序中的主题会更改为 Holo 主题,我可以弄清楚它何时发生,所以当我按下 Toolbar 中的菜单项时>NavigationDrawler 他们的背景变成蓝色,就像 Holo 主题

我哪里出错了,为什么会这样?

【问题讨论】:

    标签: android themes android-toolbar android-theme android-styles


    【解决方案1】:

    您可以发布您的 Android 清单吗?也许某些活动会覆盖基本应用程序样式?

    【讨论】:

    • 我打赌 AppTheme 和 Theme.Translucent 不一样?您的活动不使用相同的样式...
    • Activity 节点上的每个 android:theme 属性都会覆盖基本应用样式
    • Theme.Translucent 是 Facebook 登录 Activity 的标准样式。 AppTheme 是我的自定义主题。那我该怎么办?
    • 您应该在应用程序节点上应用您的自定义主题并删除活动上的任何属性。我不知道您是否必须删除 Facebook 的...
    • 因为你的基本主题实际上不是你的自定义主题,没有风格的活动变成了全息