【问题标题】:Toolbar with PreferenceActivity app:theme is not working带有 PreferenceActivity 应用程序的工具栏:主题不起作用
【发布时间】:2015-08-04 09:00:46
【问题描述】:

我正在使用以下代码添加带有 PreferenceActivity 的工具栏:

<?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="@color/actionbar_color"
    android:minHeight="?attr/actionBarSize"
    android:paddingTop="0dp"
    app:navigationContentDescription="@string/abc_action_bar_up_description"
    app:navigationIcon="?attr/homeAsUpIndicator"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar" />

代码片段:

LinearLayout root = (LinearLayout) findViewById(android.R.id.list).getParent().getParent().getParent();
        Toolbar bar = (Toolbar) LayoutInflater.from(this).inflate(R.layout.app_bar_settings, root, false);
        root.addView(bar, 0); // insert at top

使用 PreferenceActivity 成功显示工具栏 但是根据我的主题app:theme="@style/Base.ThemeOverlay.AppCompat.Dark.ActionBar,操作栏向上箭头、标题和操作溢出按钮是黑色的 这些应该是白色的。我该如何解决这个问题。

【问题讨论】:

    标签: android android-theme android-toolbar


    【解决方案1】:

    通过从工具栏访问导航图标,我们可以改变颜色

    toolbar.getNavigationIcon().setColorFilter(color, PorterDuff.Mode.SRC_IN);
    

    如果它不起作用,试试这个

    toolbar.getNavigationIcon().mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-15
      • 2015-09-09
      • 1970-01-01
      • 2016-07-20
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多