Projet Sin
Projet Sin

Reputation: 357

How to center logo while having no action bar menu

I'm hidding my action bar base on some condition. But when it's hided, the logo inside my toolbar is not center.

How can I fix that ?

    <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="@color/bleuClair"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:titleTextColor="@color/colorBlack"
        app:titleMarginStart="0dp">
        <ImageView
            android:padding="3dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/logo_hd"
            android:contentDescription="@string/remi_logo_desc" />
    </android.support.v7.widget.Toolbar>

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

Upvotes: 0

Views: 39

Answers (2)

Panicum
Panicum

Reputation: 824

Adding one extra LinearLayout with android:gravity="center" should help:

 <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/bleuClair"
        app:popupTheme="@style/AppTheme.PopupOverlay"
        app:titleTextColor="@color/colorBlack"
        app:titleMarginStart="0dp">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center">

        <ImageView
            android:padding="3dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/logo_hd"
            android:contentDescription="@string/remi_logo_desc" />

    </LinearLayout>


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

Upvotes: 0

VikaS GuttE
VikaS GuttE

Reputation: 1704

Try This way -

<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="@color/bleuClair"
    app:popupTheme="@style/AppTheme.PopupOverlay"
    app:titleTextColor="@color/colorBlack"
    app:titleMarginStart="0dp">

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="vertical">

    <ImageView
        android:padding="3dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:src="@drawable/logo_hd"
        android:contentDescription="@string/remi_logo_desc" />

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

Upvotes: 1

Related Questions