Positionnement des éléments de menu à gauche de l'ActionBar en nid d'abeille
-
24-10-2019 - |
Question
Je veux placer certains éléments de menu à gauche de ActionBar de Honycomb, mais ont trouvé aucune documentation montrant comment faire cela. On dirait qu'il devrait être possible depuis l'application Contacts a la recherche immédiatement à gauche de la barre de navigation. Toute idée de la façon de définir les éléments de menu sur le côté gauche?
La solution
Le ActionBar a un support pour une mise en page personnalisée entre l'icône de l'application et les icônes de ActionBar réguliers. Exemple:
// Set the custom section of the ActionBar with Browse and Search.
ActionBar actionBar = getActionBar();
mActionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom, null);
actionBar.setCustomView(mActionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
Autres conseils
Voici ce qui fonctionne pour moi comme un rêve: dans l'activité que j'ai ceci:
//hiding default app icon
ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
//displaying custom ActionBar
View mActionBarView = getLayoutInflater().inflate(R.layout.my_action_bar, null);
actionBar.setCustomView(mActionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM)
my_action_bar.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/turquoise">
<ImageButton
android:id="@+id/btn_slide"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="@null"
android:scaleType="centerInside"
android:src="@drawable/btn_slide"
android:paddingRight="50dp"
android:onClick="toggleMenu"
android:paddingTop="4dp"/>
</RelativeLayout>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow