Je veux faire des boutons qui ressemblent à ceci ce qui suit:
p>
J'ai semblé assez difficile pour les ICS préréglés dans le paquet Android.Widget, mais je ne trouve aucune. Je pense qu'il doit être un moyen facile, car ils semblent être thématiques de toute la version du système d'exploitation. Si quelqu'un sait un moyen de faire ressembler des boutons, je serais un campeur heureux. P>
4 Réponses :
Si vous souhaitez le faire sur tous les appareils (et versions d'Android), vous voulez essentiellement un bouton sans fond ou un fond solide avec des bordures en haut et en bas. P>
Le seul moyen d'ajouter des frontières correctement dans Android consiste à utiliser l'outil fourni avec le SDK Android ou l'ADT appelé Draw9Patch. C'est un simple petit outil qui fera le travail. Si vous avez besoin d'aide pour l'utiliser, votre meilleur pari est de rechercher une vidéo YouTube car il peut être difficile d'utiliser la première fois. P>
Merci. Je travaille juste sur une maquette en ce moment, je vais donc économiser le temps intensif pour plus tard. Je suis certain que cela fonctionnerait cependant.
Oui, ça va certainement. Ne t'inquiète pas. Cela vous donnera des maux de tête, mais c'est une compétence inestimable à apprendre sur Android. Regarder un couple de tutoriels était la seule façon dont j'ai été vraiment capable de l'obtenir. Maintenant, la chose que je peux retirer, elle sont assez folles. Une fois que vous avez obtenu cela, vous voudrez peut-être examiner cette conférence avancée =) YouTube.com/watch ? v = xtyzoo7njrq
Et ceci est également, le dernier protégé, je vous laisserai avec Draw9Patch. plus.google.com/u/0/113735310430199015092/posts/1bk1b6wsygl
a joué un peu sur cette question. Est-ce qu'une solution basée sur des linéarlayouts avec des vues 1DP en tant que diviseurs et fond transparent pour obtenir le minimalisme sur les boutons.
p>
Nous voulons que les boutons changent d'adéquation en fonction de l'état du bouton. (Plus d'informations sur cela ici Bonjour Tutoriel de formulaire ) . Nous changeons la couleur d'arrière-plan afin que l'utilisateur obtienne une indication lorsque vous appuyez sur la touche. P>
borness_background.xml (va dans le dossier digue) p>
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="8dp" android:orientation="vertical" > <TextView android:layout_width="fill_parent" android:layout_height="0dp" android:gravity="center" android:layout_weight="1.0" android:textSize="14sp" android:text="@string/borderless" /> <TextView android:id="@+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginBottom="8dp" android:textSize="12sp" android:autoLink="web" android:text="@string/source1" /> <View android:id="@+id/horizontal_divider1" android:layout_width="fill_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" /> <LinearLayout android:layout_width="fill_parent" android:layout_height="wrap_content" > <Button android:id="@+id/button1" android:layout_width="wrap_content" android:layout_height="48dp" android:layout_weight="1.0" android:background="@drawable/borderless_background" android:textColor="@android:color/white" android:textSize="16sp" android:text="Cancel" android:onClick="cancel" /> <View android:id="@+id/vertical_divider" android:layout_width="1dip" android:layout_marginTop="8dp" android:layout_marginBottom="8dp" android:layout_height="fill_parent" android:background="@android:color/darker_gray" /> <Button android:id="@+id/button2" android:layout_width="wrap_content" android:layout_height="48dp" android:layout_weight="1.0" android:background="@drawable/borderless_background" android:textColor="@android:color/white" android:textSize="16sp" android:text="Next" android:onClick="next" /> </LinearLayout> <View android:id="@+id/horizontal_divider2" android:layout_width="fill_parent" android:layout_height="1dp" android:background="@android:color/darker_gray" /> </LinearLayout>
Si vous recherchez la mise en page XML du bouton d'ICS Android, comme celle de la capture d'écran suivante, voici la disposition XML que j'ai trouvée à partir du code source d'OS Android.
P>
<!-- Copyright (C) 2008 The Android Open Source Project Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. --> <!-- OK confirm and cancel buttons. --> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:divider="?android:attr/dividerHorizontal" android:showDividers="beginning" android:paddingTop="16dip"> <LinearLayout style="?android:attr/buttonBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:measureWithLargestChild="true"> <LinearLayout android:id="@+id/leftSpacer" android:layout_weight="0.25" android:layout_width="0dip" android:layout_height="wrap_content" android:orientation="horizontal" android:visibility="gone" /> <Button android:id="@+id/cancel_button" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="left" android:layout_weight="1" android:text="@string/cancel" android:maxLines="2" style="?android:attr/buttonBarButtonStyle" /> <Button android:id="@+id/ok_button" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_gravity="right" android:layout_weight="1" android:text="@string/install" android:maxLines="2" android:filterTouchesWhenObscured="true" style="?android:attr/buttonBarButtonStyle" /> <LinearLayout android:id="@+id/rightSpacer" android:layout_width="0dip" android:layout_weight="0.25" android:layout_height="wrap_content" android:orientation="horizontal" android:visibility="gone" /> </LinearLayout> </LinearLayout>
Une bonne trouvaille et répond à quelque chose qui n'est vraiment pas documenté.
J'ai trouvé une solution très simple que:
Source: https://gist.github.com/2373644 P >
Contenu: P>
<!-- A button bar is a set of buttons at the bottom of an activity. An example is an AlertDialog with OK/Cancel buttons. Note that something similar can be accomplished using a split action bar and text-only action buttons, but this is an alternate presentation that's often preferred. --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent" android:divider="?android:attr/dividerHorizontal" android:showDividers="middle"> <TextView android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:gravity="center" android:text="Hello World" /> <LinearLayout style="?android:attr/buttonBarStyle" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <Button style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="One" /> <Button style="?android:attr/buttonBarButtonStyle" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="Two" /> </LinearLayout> </LinearLayout>
Faites-moi savoir si vous avez besoin d'aide avec Draw9Patch. Je l'ai déjà fait, alors je serais heureux d'aider.