0

How can I add text in a drawable image button without adding text with classic way at main xml file with the command "android:text="test", but I want to add the text of the image button in the drawable xml (code 2).

Code 1 - main.xml:

     <ImageButton
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:src="@drawable/start_off"
        android:text="TEST"
        android:background="@null"/>

Code 2 - drawable xml button:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<!-- Define the background properties like color etc -->
<item android:id="@android:id/background">
    <shape
        android:shape="oval">

        <gradient
            android:angle="270"
            android:startColor="#990000"
            android:endColor="#ff0000"
            />

        <corners
            android:radius="4dp"
            />

        <size
            android:width="120dp"
            android:height="120dp"
            />

    </shape>
</item>

2 X
  • 77
  • 10
  • Beacuse I use this drawbale code to update via USB the state of a button (if it is on or no) and I can only use image button. – 2 X Jan 19 '16 at 19:07

1 Answers1

0

Why not use a button and have the drawable be the background? Here is a good link to look here

Community
  • 1
  • 1
Droid Chris
  • 3,455
  • 28
  • 31