Android 在AppBar中间显示应用程序图标

Android 在AppBar中间显示应用程序图标,android,android-layout,Android,Android Layout,现在,作为一个例子,该应用程序如下所示: 如何通过编程或使用xml使appbar看起来像这样: 我尝试将appbar图标设置为背景,但它看起来很奇怪。您可以使用android:show=“always”将应用程序图标作为菜单项添加到appbar 另一种解决方法是将imageView放置在appBar内的工具栏中。然后,可以通过xml代码或编程方式更改此imageview的位置 <android.support.design.widget.AppBarLayout and

现在,作为一个例子,该应用程序如下所示:

如何通过编程或使用xml使appbar看起来像这样:


我尝试将appbar图标设置为背景,但它看起来很奇怪。

您可以使用android:show=“always”将应用程序图标作为菜单项添加到appbar

另一种解决方法是将imageView放置在appBar内的工具栏中。然后,可以通过xml代码或编程方式更改此imageview的位置

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

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?actionBarSize"
        android:background="?attr/colorPrimary"
        android:theme="@style/ToolbarColoredBackArrow"
        app:popupTheme="@style/AppTheme.PopupOverlay" >

        <ImageView
       android:id="@+id/indicator"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_margin="@dimen/margin_small"/>

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

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