dotnet/android

How to make buttons have rounded corners???

BantiPlayz opened this issue · 1 comments

Android framework version

net9.0-android

Affected platform version

VS 2022

Description

I make a new xml file under resources/drawable, and call it rounded_button.xml including the relevant code to acquire the rounded shape for the buttons.
After, I use this drawable resource in activity_main.xml and apply it as a drawable background for the button (@drawable/button_rounded). This is the most simple way I've thought of doing this. However, it just doesn't seem to work. It was at first a build issue so I figured changed the build type of the rounded_button.xml to Androidresource would fix this. While the errors were fixed the rounded buttons aren't showing and the button just appears as the default button. I don't know how to achieve this rounded button look. PLEASE HELP

Steps to Reproduce

  1. New project, create necesssary code, build the project.

Did you find any workaround?

No

Relevant log output

rounded_button.xml code is below:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <solid android:color="#FF6200EE"/> <!-- Button background color -->
    <corners android:radius="16dp"/> <!-- Corner radius -->
    <padding android:left="10dp" android:top="10dp" android:right="10dp" android:bottom="10dp"/>
</shape>

activity_main.xml code is below:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <Button
        android:id="@+id/myButton"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/button_rounded"
        android:text="Click Me"
        android:layout_centerInParent="true"/>

</RelativeLayout>

Ultimately, all .NET for Android does is provide generated wrappers that allow you to call Google’s Android API. We do not have much expertise in how to use those API’s properly.

You will likely need to use the Android API documentation and relevant forums to determine how to write code for your desired outcome.

One guess might be that you say the file is named rounded_button.xml but you are calling it as @drawable/button_rounded.