如何将图像添加到工具栏

时间:2017-03-26 03:39:24

标签: java android xml

我对编码非常陌生,我一直在试图弄清楚如何将图像添加到Android的工具栏中。为什么这不起作用?

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.design.widget.CoordinatorLayout
    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="com.example.admin.prototypeapp.MainActivity">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:theme="@style/AppTheme.AppBarOverlay">

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

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:layout_margin="@dimen/fab_margin"
            app:srcCompat="@android:drawable/ic_dialog_email" />

          <android.support.v7.widget.Toolbar
            style="@style/ToolBarStyle"
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?attr/colorPrimary"

            <ImageView
                android:contentDescription="@string/logo"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:src="@drawable/white_logo_transparent"/>

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

        <include layout="@layout/content_main" />

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

是否可以插入这样的图像?

它告诉我/android.support.v7.widget.Toolbar应该是/android.support.design.widget.CoordinatorLayout

新秀的错误?有没有更好的方法呢?

1 个答案:

答案 0 :(得分:0)

So, total complexity would be O(1)+O(n). Where O(1)= look up in HashMap O(n)= iterate all the elements 的xml标记未关闭。请尝试:

Toolbar
相关问题