D
D
dimasik1002002018-08-11 17:36:49
Java
dimasik100200, 2018-08-11 17:36:49

How to change the background of an ImageButton?

I have a Relative layout container in the form of a circle, and inside it there is an Image button that needs to change the background. (I need a round button of a certain color and with an icon inside) How to do this if the backgraund says

android:background="?attr/selectableItemBackgroundBorderless"

Here is the full container code
<RelativeLayout
            android:id="@+id/fragment_input_send_container"
            android:layout_width="45dp"
            android:layout_height="45dp"
            android:background="@drawable/ugli"
            android:layout_alignParentEnd="true"
            android:layout_centerVertical="true">

            <ImageButton
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="?attr/selectableItemBackgroundBorderless"
                android:clickable="true"
                android:focusable="true"
                android:src="@drawable/microphone"
                android:tint="@color/colorAccent"/>

        </RelativeLayout>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2018-08-11
@red-barbarian

1) in the layer-list make a button with an icon and a pressed button
in the selector make a button with two states (or more) (the first with press=true)
make background = your selector
2) make the two icons round - one is pressed the other is not. make a selector on them and insert it into the background of the button
3) make a CardView. make it clickable and round the corners to a circle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question