如何更改工具栏选项背景的颜色

瓦希德·阿米里(Vahid Amiri)

我想更改工具栏中选项的浅色背景以及尝试复制内容时出现的部分。现在真的很糟糕:

在此处输入图片说明

这是我的styles.xml:

<?xml version="1.0" encoding="utf-8" ?>
<resources>
  <style name="MyTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
    !-- All customizations that are NOT specific to a particular API-level can go here. -->
    <item name="windowNoTitle">true</item>
    <item name="colorPrimary">@color/primary</item>
    <item name="colorPrimaryDark">@color/primary_dark</item>
    <item name="colorAccent">@color/accent</item>
     <item name="android:textColorPrimary">@color/primary_text</item>
     <item name="android:textColorSecondary">@color/secondary_text</item>

  </style>

  <!-- Application theme. -->
  <style name="MyTheme" parent="MyTheme.Base">
  </style>

  <style name="MyTheme.ToolBar" parent="MyTheme.Base">
    <item name="android:textColorPrimary">@android:color/white</item>
    <item name="android:textColorSecondary">@android:color/white</item>
  </style>

  <style name="MyTheme.NavMenu" parent="MyTheme.Base">
    <item name="android:textColorPrimary">@color/gray</item>
  </style>

  <style name="MyTheme.RightMenu" parent="MyTheme.Base">
    <item name="android:textColorPrimary">@color/black</item>
  </style>
</resources>

您可能已经注意到我正在使用,NoActionBar因为我正在使用工具栏。在我的main.xml上:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">
<!-- your content layout -->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
    <!-- Toolbar instead of ActionBar so the drawer can slide on top -->
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            app:theme="@style/MyTheme.ToolBar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/abc_action_bar_default_height_material"
            android:background="?attr/colorPrimary"
            android:minHeight="?attr/actionBarSize" />
    <!-- Real content goes here -->
        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1" />
    </LinearLayout>
    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:id="@+id/nav_view"
        app:headerLayout="@layout/nav_view_header"
        app:menu="@layout/nav_view_menu"
        app:theme="@style/MyTheme.NavMenu" />
</android.support.v4.widget.DrawerLayout>
૯૯

在工具栏中尝试以下操作:

app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"

在ShareAction MenuItem中未使用的AppCompat工具栏popupTheme

这是与AppBarLayout

<android.support.design.widget.AppBarLayout
            android:id="@+id/app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbarmain"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/ColorPrimary"
                app:layout_collapseMode="pin"
                app:layout_scrollFlags="scroll|enterAlways"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

看看这个也:

app:popupTheme="@style/ThemeOverlay.AppCompat.Light"

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何更改Polymer(1.0)纸工具栏的背景颜色?

如何在BottomBarPage中更改工具栏背景颜色

Swift 3 / IQKeyboardManager:如何更改工具栏的背景颜色,完成颜色,箭头颜色?

如何更改工具栏控件的颜色?

如何更改SFSafariViewController工具栏颜色

Android 工具栏菜单项背景

更改工具栏背景会产生Lavendar颜色

代号一-更改工具栏的背景颜色

从代码背后更改工具栏项目的背景颜色

Android Material Design-CollapsingToolbarLayout折叠后如何更改工具栏的背景颜色

如何使用xul更改在firefox中添加的javascript中工具栏按钮的背景颜色

方向改变时如何保留工具栏背景颜色?

如何设置复制和粘贴工具栏的背景颜色?

如何以编程方式获取工具栏背景颜色?

如何在不创建新工具栏布局的情况下使用XML更改Android工具栏背景颜色

如何更改工具栏中 SearchView 的文本颜色?

如何更改工具栏主页图标颜色

当折叠的工具栏折叠时,如何更改其颜色?

如何在Swift中更改工具栏颜色

如何更改工具栏上项目的颜色

如何更改工具栏中图标的颜色?

如何在单击按钮时更改工具栏颜色?

温泉工具栏背景颜色不变

更改工具栏的后退箭头颜色

更改工具栏中的标题颜色?

无法更改工具栏的颜色

更改工具栏OnsenUi的颜色

如何在Android中更改折叠工具栏的文本颜色和折叠工具栏的后退按钮颜色

更改折叠工具栏的背景