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 einer button
InformationsquelleAutor Anmol Wadhwa | 2013-09-13
Schreibe einen Kommentar