0

I want to make a perfect square shaped button and the shape looks like this:

enter image description here

Here, xml is :

<Button
    android:id="@+id/button3"
    android:layout_width="@dimen/box_size"
    android:layout_height="@dimen/box_size"
    android:layout_weight="50"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.598"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.146" />

I want to delete the blank between the line and blue square and don't know how to.

I tried to make an Image button and it also gave me unwanted result.

MooNChilD Song
  • 225
  • 1
  • 9
  • Hey @MooNChild Song, Please refer this link [https://stackoverflow.com/questions/10124919/can-i-draw-rectangle-in-xml ] – piyushpk Nov 09 '20 at 11:14

1 Answers1

1

One way to solve this (Which I use), is to create a "Layout Resource File" and set it as the background for your button.

You could do this for example: create a "custom_background.xml" file (or any name you like), and write in it:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
    <solid android:color="@color/colorPrimary" />
</shape>

Then add in the button code:

android:background="@drawable/button_background"
asj2020
  • 11
  • 1