2016-09-23 26 views
0

Ich verwende eine benutzerdefinierte Symbolleiste, die auf diese Weise aufgebaut ist:Android Optionsmenü oberen und unteren Rand

<android.support.v7.widget.Toolbar 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingLeft="0dp" 
    android:contentInsetStart="0dp" 
    android:contentInsetLeft="0dp" 
    android:contentInsetEnd="0dp" 
    android:contentInsetRight="0dp" 
    app:contentInsetLeft="0dp" 
    app:contentInsetStart="0dp" 
    app:contentInsetRight="0dp" 
    app:contentInsetEnd="0dp"> 

    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/deepDarkVioletToolbar"> 

     <ImageView 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="@dimen/defaultMargin" 
      android:layout_marginTop="16dp" 
      android:background="@drawable/logo" /> 

    </RelativeLayout> 

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

Es ist Nutzung:

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context=".views.activities.MainActivity"> 

    <include 
     android:id="@+id/toolbar" 
     android:layout_height="?attr/actionBarSize" 
     android:layout_width="match_parent" 
     android:layout_alignParentTop="true" 
     layout="@layout/default_toolbar" /> 

    <!-- other views go here --> 

</RelativeLayout> 

Ich versuche Optionen-Menü hinzufügen, um meine Anwendung, so zu tun, um, dass ich diese Methode, um meine Aktivität hinzugefügt:

@Override 
public boolean onCreateOptionsMenu(Menu menu) { 
    ((Toolbar)findViewById(R.id.toolbar)).inflateMenu(R.menu.main_menu); 

    return true; 
} 

Und mein main_menu Layout:

Das Problem ist, dass das Optionsmenü einige Ränder (Paddings?) - oben und unten hat. Sie können an diesem Screenshot einen Blick:

enter image description here

Ich habe drei Fragen (von denen die ersten das wichtigste ist):

  1. Wie kann ich diese Ränder loszuwerden?
  2. android:icon auf Menüeintrag hat keinen Effekt, also wie lege ich ein Symbol dort? Wenn das nicht möglich ist:
  3. Wie ändert man die Farbe dieser drei Punkte?

Antwort

0

Für Symbolfarbe ändern Sie mit diesem

MenuItem find = menu.findItem(R.id.find_icon); 
Drawable drawable = menuItem.getIcon(); 
if (drawable != null) { 
    drawable.mutate(); 
    drawable.setColorFilter(Color.WHITE, PorterDuff.Mode.SRC_ATOP); 
} 
Verwandte Themen