Search code examples
androidandroid-studioandroid-5.0-lollipop

Add image to top navigation bar in Android Lollipop


I want to know the ways of adding an image to Top Navigation bar in Android lollipop instead of the title of the application.

Like in the image below : enter image description here


Solution

  • The Toolbar is a ViewGroup, so you can just add a child ImageView to it:

    <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>