将图像添加到Android Lollipop的顶部导航栏

时间:2016-05-12 14:59:40

标签: android android-studio android-5.0-lollipop

我想知道在Android棒棒糖中向Top Navigation栏添加图片的方法,而不是应用程序的标题。

如下图所示: enter image description here

2 个答案:

答案 0 :(得分:2)

工具栏是一个ViewGroup,因此您只需向其添加一个子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="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/image"/>
    </android.support.v7.widget.Toolbar>

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

答案 1 :(得分:1)

您可以使用工具栏作为应用程序ActionBar(通过setActionBar或setSupportActionBar)。

工具栏是一个ViewGroup,因此您可以根据需要更改其布局(将imageview添加到您的图像中)