Button with image and text.

I have a button on which I place the image

I was told that I needed to reduce the image size by 30%, so I created a scalable scale and put it in the button selector

Unfortunately, the image does not appear on the button as expected.

here is my code for the button

<Button
    android:id="@+id/btnMain"
    style="@style/buttonMenuAppearance"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:drawableTop="@drawable/selector_ic_main"
    android:text="@string/btnMain" />

my selector

    <selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:drawable="@drawable/scaled_ic_main_disabled" android:state_enabled="false"></item>
    <item android:drawable="@drawable/ic_main_pressed" android:state_enabled="true" android:state_pressed="true"></item>
    <item android:drawable="@drawable/ic_main_normal" android:state_enabled="true" android:state_pressed="false"></item>
    <item android:drawable="@drawable/ic_main_normal"></item>

    </selector>

my scalable available

<scale xmlns:android="http://schemas.android.com/apk/res/android"
android:drawable="@drawable/ic_main_disabled"
android:scaleGravity="center_vertical|center_horizontal"
android:scaleHeight="30%"
android:scaleWidth="30%" />

how he looked before the scale:     enter image description here

what it looks like after the scale: enter image description here

Why is my image not showing?

+3
source share
1 answer

Your “scaled image” is called “scale”, not “scaled_ic_main_disabled”, so your selector doesn't display anything (I think you have no objects named “scaled_ic_main_disabled”)

"scaled_ic_main_disabled" "" .

0

All Articles