So fügen Sie ein Bild zu einem button in android
Ich Frage mich, wie ich ein Bild in eine Schaltfläche.
Ich habe versucht, verwenden Sie "android:icon="@drawable/suchen.png"
und ich füge dieses Bild in den drawable-hdpi Ordner, aber das Bild wird nicht angezeigt. Ich entwickle eine Anwendung für das nexus 4, also ich weiß nicht, welche Größe das Bild sein soll. Das Bild, das ich bin versucht hinzuzufügen, ist eine normale Suche Symbol in der Kontakt-manager des nexus 4.
Den code, den ich bisher geschrieben haben.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/lbl_group_coworkers"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Coworkers"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<TextView
android:id="@+id/lbl_group_family"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Family"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"/>
<TextView
android:id="@+id/lbl_group_friends"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Friends"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="0dip"
android:layout_weight="1"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="@+id/Button1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.70"
android:icon="@drawable/search.png" />
<Button
android:id="@+id/Button2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="addGroup"
android:icon="@drawable/addgroup.png"/>
<Button
android:id="@+id/Button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.11"
android:text="@string/Button3" />
</LinearLayout>
</LinearLayout>
- Verwenden Sie eine
ImageButton
statt einerbutton
Du musst angemeldet sein, um einen Kommentar abzugeben.
Hinzufügen
background
undimage
undtext
zur gleichen Zeit.Ersetzen Sie einfach
mit
Können Sie auch Attribute im Taste Layout Eigenschaften-Definition Bild-Quelle in der Schaltfläche platziert werden
android:background
undandroid:text
in die Schaltfläche Attribute zusammen 🙂".png"
im Namen, es gibt einen Fehler, nämlich Ihre Ressource kann nicht gefunden werden. Verwenden Sie einfachandroid:background="@drawable/addgroup"
verwenden Sie das Attribut
Können Sie den hintergrund der Schaltfläche verwenden :
android:background="@drawable/..."
Bitte machen drawable Ordner in res und erstellen buttonanimation.xml in drawable Ordner
Und verwenden Sie diese buttonanimation in layout-Schaltfläche hintergrund.