Est-il possible de créer sur mesure actionbar comme écran ci-dessous, en utilisant la bibliothèque ActionBarSherlockAndroid Terminé Annuler actionbar
Répondre
Voici comment vous faites réellement dans xml
utilisation de la mise en page de Roman en nid d'abeille et au-dessus
/layout-v11/actionbar_custom_view_done_discard.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:divider="?android:attr/dividerVertical"
android:dividerPadding="12dp"
android:orientation="horizontal"
android:showDividers="middle" >
<include layout="@layout/actionbar_discard_button" />
<include layout="@layout/actionbar_done_button" />
</LinearLayout>
/layout- v11/actionbar_discard_button.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionbar_discard"
style="?android:actionButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selectable_background_mystyle" >
<TextView style="?android:actionBarTabTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingRight="20dp"
android:drawableLeft="@drawable/ic_menu_cancel"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:text="@string/menu_cancel" />
</FrameLayout>
/layout-v11/actionbar_done_button.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionbar_done"
style="?android:actionButtonStyle"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/selectable_background_mystyle" >
<TextView
style="?android:actionBarTabTextStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableLeft="@drawable/ic_menu_save"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:paddingRight="20dp"
android:text="@string/menu_save" />
</FrameLayout>
et rétroporter avec ActionBar Sherlock
/layout/actionbar_custom_view_done_discard.xml
<LinearLayout 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"
android:orientation="horizontal" >
<include layout="@layout/actionbar_discard_button" />
<View
android:layout_width="0.5dp"
android:layout_height="match_parent"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:background="#55FFFFFF" />
<include layout="@layout/actionbar_done_button" />
</LinearLayout>
/layout/actionbar_discard_button. xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionbar_discard"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingRight="20dp"
android:background="@drawable/selectable_background_mystyle" >
<TextView
style="@style/Widget.Sherlock.ActionBar.TabText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableLeft="@drawable/ic_menu_cancel"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:text="@string/menu_cancel" />
</FrameLayout>
/layout/actionbar_done_button.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/actionbar_done"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:paddingRight="20dp"
android:background="@drawable/selectable_background_mystyle" >
<TextView
style="@style/Widget.Sherlock.ActionBar.TabText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:drawableLeft="@drawable/ic_menu_save"
android:drawablePadding="8dp"
android:gravity="center_vertical"
android:text="@string/menu_save" />
</FrameLayout>
Vous devriez pouvoir réaliser cela via setCustomView()
. Roman Nurik a a G+ post on ways of implementing DONE+DISCARD, avec source code available. Bien que son code n'utilise pas ActionBarSherlock, je suspecte qu'il sera transféré. Cependant, gardez à l'esprit que les arrière-plans des boutons sont légèrement différents sur Android 2.x que sur 3.0+, et que vous devrez peut-être faire un peu plus de travail pour que vos boutons apparaissent dans l'espace de la barre d'actions. que tu veux.
merci de l'essayer. –
Pour compléter les instructions d'utilisation @Vlasto Benny Lava has described, voici le code qui définit en fait la ActionBar (basé sur le original code de l'API 14 par Roman Nurik) - adapté pour ActionBarSherlock utilisation.
// BEGIN_INCLUDE (inflate_set_custom_view)
// Inflate a "Done/Cancel" custom action bar view.
final LayoutInflater inflater = (LayoutInflater) getSherlockActivity().getSupportActionBar()
.getThemedContext().getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done_discard,
null);
customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// "Done"
Toast.makeText(getActivity(), "DONE", Toast.LENGTH_SHORT).show();
}
});
customActionBarView.findViewById(R.id.actionbar_discard).setOnClickListener(
new View.OnClickListener() {
@Override
public void onClick(View v) {
// "Cancel"
Toast.makeText(getActivity(), "DISCARD", Toast.LENGTH_SHORT).show();
}
});
// Show the custom action bar view and hide the normal Home icon and title.
final ActionBar bar = getSherlockActivity().getSupportActionBar();
bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM, ActionBar.DISPLAY_SHOW_CUSTOM
| ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
bar.setCustomView(customActionBarView, new ActionBar.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// END_INCLUDE (inflate_set_custom_view)
Je l'utilise pour un Fragment
où le getSherlockActivity()
. S'il est utilisé dans Activity
, vous pouvez omettre librement cette partie.
Il y a deux endroits où vous pouvez configurer cette ActionBar personnalisée:
dans Activitys
onCreate()
(ou fragmentsonAttach()
),dans activitées/Fragments
onCreateOptionsMenu()
.
Sur procédure comment revenir ActionBar à la forme « originale » (après la DONE ou Rejeter a été sélectionné), vous pouvez vous référer à this answer.
- 1. ActionBar dans Android 1.6
- 2. débordement actionbar Menu android
- 3. Personnaliser ActionBar dans Android
- 4. Android Translucide ActionBar
- 5. Android masquant ActionBar
- 6. Android ActionBar et Cursor
- 7. Android: WebView ActionBar (Honeycomb)?
- 8. Android ActionBar Texte Couleur
- 9. Personnalisez Android ActionBar
- 10. Articles Android ActionBar action
- 11. Android Actionbar + FragmentActivity
- 12. Android ActionBar Compatibilité
- 13. ActionBar Crash Android
- 14. Bouton et onglets Android ActionBar
- 15. Android 3.0 ActionBar Gmail Rechercher
- 16. android Greendroid ActionBar utilisant ActivityGroup
- 17. Android Actionbar Tabs + Fragments + Service
- 18. Android: ActionBar ouvre toujours SettingsActivity
- 19. Personnaliser ActionBar TabBar dans Android?
- 20. Android ActionBar n'est pas créé
- 21. Android Toggle Button dans ActionBar
- 22. Android ActionBar Tabulations et Fragments
- 23. Contexte AsyncTask Android Terminé
- 24. Comment annuler un minuteur avant qu'il ne soit terminé
- 25. Android annuler tous AlarmManager
- 26. annuler android MediaController bouton
- 27. Service Android annuler oncreate
- 28. Android annuler un mediarecording
- 29. Android - action annuler bouton
- 30. Comment ajouter un bouton dans ActionBar (Android)?
J'ai implémenté et changé le TextView en Bouton. Maintenant, je ne sais pas où je définis la méthode onClick au bouton. –
bien, tout fonctionne de la même manière, comme dans cet exemple https://code.google.com/p/romannurik-code/source/browse/misc/donediscard – urSus