Comment mettre l'icône à gauche de la barre d'onglets de l'action
-
26-10-2019 - |
Question
J'utilise le ActionBar.Tab, et ils apparaissent toujours à gauche de l'écran. Je veux mettre l'icône d'activité à gauche des onglets, mais apparaissent toujours à droite des onglets. Comment puis-je déplacer leur position à l'endroit où je veux?
La solution
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>
Autres conseils
// utiliser votre point de vue xml personnalisé pour afficher l'icône à gauche
View actionBarView = getLayoutInflater().inflate(R.layout.action_bar_custom_view, null);
actionBar.setCustomView(actionBarView);
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
sur votre méthode de onCreate()
si vous êtes sur l'activité
actionBar.addTab(actionBar.newTab()
.setIcon(<the icon you want>)
.setText(mSectionsPagerAdapter.getPageTitle(i))
.setTabListener(this));
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow