2016-06-29 6 views
0

Ich möchte das Logo in der Mitte der Aktionsleiste anzeigen. Hier ist mein Layout-Code: Der folgende Code sollte funktionieren, aber warum nicht? Bitte helfen Sie mirWie Logo in der Mitte der Actionbar Symbolleiste in Android platzieren?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

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

</LinearLayout> 

Und im onCreate()

getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM); 
    getSupportActionBar().setCustomView(R.layout.custom_logo); 
+0

http://stackoverflow.com/questions/32857438/center-position-of-logo-in-action-bar-android – USKMobility

+0

Ich habe versucht, auf diesen Link, aber es funktionierte nicht für mich arbeiten –

+0

mein Logo nicht –

Antwort

2

Ihre Toolbar ist wie ein Viewgroup, die andere views.So einen einfacheren Ansatz halten kann, wird eine Image in der Werkzeugleiste zu platzieren. Für zB: -

<android.support.v7.widget.Toolbar 
     xmlns:app="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/toolbar" 
     android:layout_width="match_parent" 
     android:layout_height="?attr/actionBarSize" 
     android:background="@color/material_blue" 
     android:elevation="5dp" 
     android:minHeight="?attr/actionBarSize" 
     android:theme="@style/ThemeOverlay.AppCompat.Dark" 
     app:theme="@style/ToolbarCustomIconColor" > 
      <RelativeLayout 
       android:id="@+id/toolbar_layout" 
       android:layout_width="match_parent" 
       android:layout_height="match_content" > 
       <ImageViewView 
        android:id="@+id/imgLogo" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_centerInParent="true" 
        android:src="@drawable/your_icon" /> 
     </RelativeLayout> 
    </android.support.v7.widget.Toolbar> 

Sie können eine benutzerdefinierte Toolbar wie diese erstellen und so oft wie Sie möchten manipulieren.