【问题标题】:How to apply different Action Bar colors to different activities?如何将不同的操作栏颜色应用于不同的活动?
【发布时间】:2015-07-27 15:51:27
【问题描述】:

我正在使用 v7 appcompat 21 库来试用 Material Theme 操作栏。我对 styles.xml 使用以下代码

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="MyTheme" parent="Theme.AppCompat">
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">#3c9cd7</item>
    <item name="colorPrimaryDark">#127fba</item>
    <item name="colorAccent">#006db0</item>
  </style>
</resources>

我使用的布局是这样的

<android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_height="wrap_content"
    android:layout_width="match_parent"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

在我的应用程序中有许多带有不同背景可绘制对象的屏幕,我希望工具栏与这些颜色相匹配。我不想使用颜色标志。 这可以仅使用 xml 文件来完成吗? 我尝试更改 android:background,它可以工作,但通知栏颜色不会随之改变。

这一切都在 Xamarin Studios 中完成。

【问题讨论】:

    标签: android android-actionbar material-design android-appcompat android-actionbar-compat


    【解决方案1】:

    如果您只想通过使用 XML 来做到这一点,那么您需要为每个活动创建具有所需颜色的单独工具栏。

    【讨论】:

    • 虽然我不能创建那么多主题..还有其他选择吗??
    【解决方案2】:

    您可以通过使用getActionBar()getSupportActionBar() 以编程方式为操作栏提供自定义布局。然后,您可以根据 Activity 完全分配不同布局的不同背景值。

    【讨论】:

    • 它只使用背景drawable,可以使用xml文件来完成...我需要更改colorPrimary以及colorPrimaryDark
    猜你喜欢
    • 2016-06-30
    • 1970-01-01
    • 2015-08-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-16
    相关资源
    最近更新 更多