2016-04-18 7 views
0

Ich habe Schaltflächen mit Text drin. Was ich will, ist die gleiche Schaltfläche ohne den Text, mit einem kleinen Symbol in der Mitte der Schaltfläche. Das Symbol muss sein, ich nehme an, ein Bild, das Sie in der Zeichnungsdatei speichern, aber wenn ich das in die Schaltfläche legt, wird es als Hintergrund festgelegt.Anpassen meiner Schaltfläche

Auch alle Bilder mit Symbolen sind Bilder mit einem schwarzen Symbol, das mit weißem Raum umgeben ist, um es zu einem Quadrat zu machen. Ich möchte meinen Knopf behalten, nur ein Symbol in der Mitte davon. Weiß jemand, wie man das macht?

Aktivität Hauptcode:

<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="vertical" 
    tools:context="com.example.rodekruis.MainActivity"> 


    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.example.rodekruis.MainActivity"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dp" 
     android:src="@drawable/rkz_logo" 
     android:layout_gravity="center" /> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginBottom="20dp" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button10" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_alignTop="@+id/button8" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Afspraak maken" /> 


     <Button 
      android:id="@+id/button8" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Bezoek tijden" /> 

     <Button 
      android:id="@+id/button9" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:background="@drawable/contact" 
      android:text="Contact" /> 

    </LinearLayout> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="10dp" 
     android:layout_marginBottom="20dp" 
     android:orientation="horizontal"> 


     <Button 
      android:id="@+id/button3" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Geef je mening!" /> 


     <Button 
      android:id="@+id/button4" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Route begeleiding" /> 

     <Button 
      android:id="@+id/button1" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_alignLeft="@+id/button5" 
      android:layout_below="@+id/button8" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:text="Specialisten" /> 

    </LinearLayout> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginTop="10dp" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button5" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1.03" 
      android:text="Brandwonden centrum" /> 


     <Button 
      android:id="@+id/button6" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text="Agenda" /> 


     <Button 
      android:id="@+id/button7" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:text="Nieuws" /> 
    </LinearLayout> 

</LinearLayout> 
</LinearLayout> 

Dies ist der Code für die obere Reihe Tasten:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context="com.example.rodekruis.MainActivity"> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="20dp" 
     android:src="@drawable/rkz_logo" 
     android:layout_gravity="center" /> 


    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_marginBottom="20dp" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button10" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_alignTop="@+id/button8" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Afspraak maken" /> 


     <Button 
      android:id="@+id/button8" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_marginRight="5dp" 
      android:layout_weight="1" 
      android:text=" Bezoek tijden" /> 

     <ImageButton 
      android:id="@+id/button9" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:src="@drawable/rkz_logo" 
      android:gravity="center" 
      android:text="Contact" /> 

    </LinearLayout> 
+0

Bitte beziehen http://stackoverflow.com/questions/18507351/how-to-create-custom -button-in-android-using-xml-styles –

Antwort

0

Verwenden Sie ImageButton Widget anstelle von Button Widget. Verwenden Sie dann android:src Tag, um das Bild festzulegen, und android:gravity="center", um die Bildgravitation in die Mitte zu setzen.

Hope it :)

UPDATE Dann ist diese versuchen helfen -

diese
<ImageButton 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@mipmap/ic_launcher" //Your image icon 
     android:background="@android:drawable/btn_default_small"/> 
+0

Danke für die Antwort, jedoch. Dies entfernt die normale Schaltfläche und verwendet das Bild als Schaltfläche. Ich möchte den normalen Knopf, und IN diesen normalen Knopf, in kleinem, ein anderes Bild behalten. Sie haben also immer noch das Quadrat als Knopf, nicht das Bild. –

+0

OK. Dann versuchen Sie diese -

+0

Es ist dahin kommen. Das Bild ist über dem Knopf, der Knopf ist noch dort, was ich will. Die Sache ist, das Bild ist zu groß, so dass es darüber geht und den Knopf viel größer macht, als es sein soll. Selbst die Icon-Bilder von Google sind zu groß. Kann ich die Größe im Code ändern? –

0

Änderung

<Button 
      android:id="@+id/button9" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:background="@drawable/contact" 
      android:text="Contact" /> 

zu

<ImageButton 
      android:id="@+id/button9" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="0dp" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="5dp" 
      android:layout_weight="1" 
      android:src="@drawable/contact" 
      android:text="Contact" /> 

wenn Sie Quadrat-Taste bearbeiten möchten nicht

<ImageButton 
       android:id="@+id/button9" 
       style="?android:attr/buttonStyleSmall" 
       android:layout_width="0dp" 
       android:layout_height="match_parent" 
       android:layout_marginLeft="5dp" 
       android:background="@android:color/transparent" 
       android:layout_weight="1" 
       android:src="@drawable/contact" 
       android:text="Contact" /> 
+0

Dies entfernt die normale Schaltfläche und verwendet das Bild als Schaltfläche. Ich möchte den normalen Knopf, und IN diesen normalen Knopf, in kleinem, ein anderes Bild behalten. Sie haben also immer noch das Quadrat als Knopf, nicht das Bild. –

0

Versuchen ImageButton. Wie der Name schon sagt, ist es eine Schaltfläche mit Bild. Um das Bild einzustellen:

android:src.

Hoffe, das hilft.

+0

Dies entfernt die normale Schaltfläche und verwendet das Bild als Schaltfläche. Ich möchte den normalen Knopf, und IN diesen normalen Knopf, in kleinem, ein anderes Bild behalten. Sie haben also immer noch das Quadrat als Knopf, nicht das Bild. –

Verwandte Themen