I want to use Android:DrawableTop on Android <item>!

Asked 2 years ago, Updated 2 years ago, 56 views

From the existing button, as follows

<Button
            android:drawableTop="@drawable/~"
            />

After implementing it, I took out the xml separately to use a different image depending on the state.

<item 
    android:drawable="@drawable/~" 
    android:state_focused="true" 
    android:state_pressed="false"/>

It works like this, but if you use Android:drawableTop, you will get an error."T" How can I make the same effect? Master, please help me.<

android drawabletop error

2022-09-21 23:22

2 Answers

If you want to show the image from the button to the top, I think it's possible in the following way.

I think you can adjust the size of the scale type (use the fitCenter to prevent the image from being broken) and adjust the bottom margin with the padding bottom.

<ImageButton
        android:layout_width="match_parent"
        android:layout_height="400dp"
        android:src="@drawable/~"
        android:scaleType="fitCenter"
        android:paddingBottom="200dp"
        android:background="@null"/>


2022-09-21 23:22

It's Nova hi!Haha

I think the way you did it is standard. It's weird that there's an error. If I share a code that I'm using well,

drawable/bg_icon_check.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@drawable/icon_check_p" android:state_selected="true" />
    <item android:drawable="@drawable/icon_check_n" />
</selector>

layout/layout_item.xml

<TextView
        android:id="@+id/view_manner"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:drawableLeft="@drawable/bg_icon_check"
        android:drawablePadding="14dp" />

It doesn't matter if it's Button. Button inherited TextView and changed it slightly. When you do this, if the condition changes, the color changes as the selector moves. Maybe there was a little bit of a problem with the code!


2022-09-21 23:22

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.