I
I
Ivan Nedzvetsky2014-08-22 23:04:18
Android
Ivan Nedzvetsky, 2014-08-22 23:04:18

How to make a round button in android?

We need a round button with ! round clickable area.
The round background is clear how it is done, but the button itself remains square, that is, when you click on the corners (where there is no background), the click is still processed.
On the picture:
How to make sure that clicks on the red area are not processed?26627a046b8249deb77719e96da5872c.png

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
Alexander Taratin, 2014-08-22
@Nezd

Check click coordinates.

K
kis92, 2014-08-23
@kis92

создаем в папке drawable файл oval_button.xml
<?xml version="1.0" encoding="utf-8"?>
<selector
  xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="oval">
            <solid android:color="#FCD366"/>
        </shape>
    </item>
</selector>

а в активити:

<Button
    android:id="@+id/button1"
   android:background="@drawable/oval_button"/>

V
Vladimir Yakushev, 2014-08-24
@VYakushev

Whether you like it or not, any View is drawn on a Canvas , which is uniquely rectangular in shape. Only a custom View is suitable for your task, in the onDraw method of which you draw a round button, and in the onKeyDown method you calculate the coordinates and decide whether the event should be processed or not, initiating an additional performClick to call subscriber handlers.

C
Copperfield, 2014-08-22
@Copperfield

Show how you set the round background for the button.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question