首页 > 解决方案 > 无法在操作栏中添加图像

问题描述

我试图在actionBar以下答案的帮助下添加图像https://stackoverflow.com/a/30998517/3836908

这是我尝试添加的图像

<?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/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="7dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <include
            android:id="@+id/tool_bar"
            layout="@layout/toolbar">
        </include>

        <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            xmlns:tools="http://schemas.android.com/tools"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:context=".MainActivity">

            <android.support.v7.widget.RecyclerView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:id="@+id/recyclerView">

            </android.support.v7.widget.RecyclerView>

        </RelativeLayout>

    </LinearLayout>


    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:itemBackground="@drawable/custom_ripple"
        app:menu="@menu/navigation_menu"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header"
        android:id="@+id/nv">

    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

结果如下: 在此处输入图像描述

它不是将图像添加到标题栏,而是创建一个新栏来显示图像。

她是我想要做的我想将图像添加到appBar下面的图像中, 在此处输入图像描述

她是我之前的实际代码

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_green_dark">

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity">

        <android.support.v7.widget.RecyclerView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/recyclerView">

        </android.support.v7.widget.RecyclerView>

    </RelativeLayout>

    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        app:itemBackground="@drawable/custom_ripple"
        app:menu="@menu/navigation_menu"
        android:layout_gravity="start"
        app:headerLayout="@layout/nav_header"
        android:id="@+id/nv">

    </android.support.design.widget.NavigationView>

</android.support.v4.widget.DrawerLayout>

标签: androidandroid-appbarlayout

解决方案


推荐阅读