Je suis en train de créer une boîte de dialogue sur Holo Theme et je veux suivre la manière par défaut du système d'exploitation pour afficher les boutons. Jusqu'à présent, j'ai créé la boîte de dialogue mais les boutons ne s'affichent pas de la même manière que dans les applications réalisées en Holo pour ICS. Comment puis-je faire cela ? Le look & feel que je souhaite obtenir est le suivant et je suis capable d'atteindre jusqu'ici
Réponses
Trop de publicités?Un peu tard, mais peut-être que cela intéresse encore quelqu'un.
ça marche plutôt bien pour moi.
...
<!--
EDIT: be carefull, "?android:attr/dividerHorizontal" is only supported since API 11
just avoid it in prior OSs.
-->
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="?android:attr/dividerHorizontal" />
<LinearLayout
style="?android:attr/buttonBarStyle"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingTop="0dip"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:measureWithLargestChild="true">
<Button
android:id="@+id/cancel"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/cancel"/>
<Button
android:id="@+id/ok"
style="?android:attr/buttonBarButtonStyle"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@android:string/ok"/>
</LinearLayout>
...
l'activité qui charge cette mise en page a besoin du thème Holo.Dialog.
android:theme="@android:style/Theme.Holo.Dialog"
C'est ce qui marche :
<LinearLayout
android:id="@+id/buttonHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/cmdSignup"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Signup" />
<Button
android:id="@+id/cmdLogin"
style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Login" />
</LinearLayout>
La propriété style="@android:style/Widget.Holo.Light.Button.Borderless.Small"
donne l'aspect plat et la sensation, et la distribution de poids de 50% est due à la combinaison de la taille de 100$ de LinearLayout
par android:layout_width="match_parent" and
Android:layout_weight="1"`pour les boutons
Vous pouvez définir le thème par le biais du xml Manifest Android ou dans le onCreate de l'activité avec setTheme(android.R.style.Theme_Holo);
La taille des boutons n'est pas liée au thème lui-même. La taille dépend de vos définitions xml. Dans l'image que vous avez envoyée, il semble que les boutons aient reçu le thème Holo, donc il n'y a pas de problème ici...
Voici une mise en page xml qui étire les boutons pour qu'ils occupent toute la largeur du dialogue :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dip"
>
<Button
android:id="@+id/okButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="OK"
/>
<Button
android:id="@+id/cancelButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Cancel"
/>
</LinearLayout>
</LinearLayout>