【问题标题】:ActionMode with AppCompat can't change background and text colors带有 AppCompat 的 ActionMode 无法更改背景和文本颜色
【发布时间】:2015-06-20 14:28:28
【问题描述】:

我正在尝试更改我的 ActionMode 的背景和文本颜色。我正在使用 API 11 和 AppCompat。

我用下面的style.xml试过了,但是ActionMode背景总是白色的,文字颜色是黑色的。 我想将文本颜色更改为白色,将背景颜色更改为蓝色。

我该如何解决这个问题?

这是我的 style.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- ActionMode -->
        <item name="actionModeStyle">@style/MyActionModeStyle</item>
    </style>


    <!-- Setup the style of the ActionMode here -->
    <style name="MyActionModeStyle" parent="@style/Widget.AppCompat.ActionMode">
        <item name="android:background">@color/blue</item>
        <item name="background">@color/blue</item>
        <item name="android:titleTextStyle">@style/MyActionModeTitle</item>

        <item name="titleTextStyle">@style/MyActionModeTitle</item>
    </style>

    <!-- Setup the text style of the ActionMode here -->
    <style name="MyActionModeTitle" parent="@style/TextAppearance.AppCompat.Widget.ActionMode.Title">
        <item name="android:textColor">#ffffff</item>
    </style>
</resources>

在我的活动中,我使用的是 android.support.v7.app.ActionBarActivity 但我使用工具栏: 这是我的 settings_activity_toolbar.xml

<?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"
    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    app:navigationContentDescription="@string/abc_action_bar_up_description"
    android:background="?attr/colorPrimary"
    app:navigationIcon="?attr/homeAsUpIndicator"
    app:title="@string/action_settings" />

【问题讨论】:

  • 你试过&lt;item name="colorPrimary"&gt;@color/primary&lt;/item&gt;吗?
  • 也发布您的活动代码。我想我找到了解决方法
  • 我仍在试图弄清楚,是什么阻止了 ActionMode 中的 textColor。我已成功更改 ActionMode 的背景颜色。您使用的是哪个版本的 AppCompat 库?
  • @4k3R 我编辑了我的问题
  • 您使用的是哪个版本的 AppCompat?检查你的 build.gradle

标签: android android-theme android-actionbar-compat android-actionmode actionmode


【解决方案1】:

也尝试设置android:actionModeStyle

<item name="android:actionModeStyle">@style/MyActionModeStyle</item>

【讨论】:

  • 这不起作用,因为我使用的是 API 11,而这仅在 API 21 中可用?
【解决方案2】:

好的,我通过用完成按钮以编程方式替换 HomeAsUpIndicator 来管理它。这就是我想要的...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-25
    • 2015-07-22
    • 1970-01-01
    • 1970-01-01
    • 2014-01-13
    • 2014-11-22
    • 1970-01-01
    • 2020-09-17
    相关资源
    最近更新 更多