android - 无法在操作栏中添加图像
问题描述
我试图在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>
它不是将图像添加到标题栏,而是创建一个新栏来显示图像。
她是我之前的实际代码
<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>
解决方案
推荐阅读
- angular - Angular 6 Form - 在 ValueChanges 之后改变值
- android - 如何通过删除触摸屏功能来支持 Amazon FireTV 硬件
- postgresql - 需要类似于 DISTINCT ON (a) AND DISTINCT ON (b) 的东西,其中正常的 DISTINCT 子句不起作用
- c++ - 使用 Boost.Beast 异步读取标头
- mysql - 双数据 MySQL JOIN
- c# - 将 SQL 转换为 LINQ 的问题
- javascript - 如何创建相互引用的表?
- ios - 重置 vuforia 地平面位置
- laravel - Laravel 会话超时剩余
- c++ - 将对象传递给多线程对象 Qt