相关疑难解决方法(0)

AppCompat样式背景传播到ToolBar中的Image

上下文

我正在使用最新的AppCompat v7 lib(21.0.0),我已将我的应用程序从ActionBar迁移到ToolBar

问题

  1. ToolBar中的图像自动获得与ToolBar相同的背景

目前SearchBox是在操作栏上设置的自定义视图(来自之前的实现)我计划切换到SearchView并相应地设置它,但我仍然对我现在面临的问题非常感兴趣.

Img背景

  1. 长按工具栏中的菜单项时,会出现带有提示文本的Toast,并且文本与ToolBar具有相同的背景.

吐司背景

我怎么能避免这个?

这是我的工具栏布局以及样式和主题

layout v_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/my_awesome_toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
    app:theme="@style/MyActionBarStyle"/>
Run Code Online (Sandbox Code Playgroud)

价值观/ styles.xml

<style name="MyActionBarStyle" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
    <item name="android:background">@color/green</item>
    <item name="android:windowActionBarOverlay">true</item>

    <!-- Support library compatibility -->
    <item name="background">@color/green</item>
    <item name="windowActionBarOverlay">true</item>
</style>
Run Code Online (Sandbox Code Playgroud)

主题

<style name="MyTheme" parent="AppBaseTheme">
    <!-- Here we setting appcompat’s actionBarStyle -->
    <!-- <item name="actionBarStyle">@style/MyActionBarStyle</item> -->

    <item name="windowActionBar">false</item>
    <!-- ...and here we setting appcompat’s color theming attrs -->
    <item name="colorPrimary">@color/green</item>
    <item name="colorPrimaryDark">@color/green_dark</item>
</style>
Run Code Online (Sandbox Code Playgroud)

问题1的解决方法1

第一个问题的解决方法是在ImageView上设置透明背景

android:background="@color/transparent"
Run Code Online (Sandbox Code Playgroud)

这并不能解决问题.

解决这两个问题

我为ToolBar设置了一个背景 …

android android-appcompat android-toolbar

25
推荐指数
2
解决办法
2万
查看次数