2

I have found this question and the solution was this code :

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >

    <solid android:color="#ffffff" />

    <corners
        android:bottomLeftRadius="8dp"
        android:bottomRightRadius="8dp"
        android:topLeftRadius="8dp"
        android:topRightRadius="8dp" />

</shape>

This code doesn't work on my PC (no rounded corners). And you ? There has been changes ?

EDIT 1: I have an error when I build the project : AAPT: error: XML or text declaration not at start of entity. (finally corrected : stupid mistake from me)

EDIT 2 : The error is now : The following classes could not be found: - corners (Fix Build Path, Edit XML) - shape (Fix Build Path, Edit XML) - solid (Fix Build Path, Edit XML) Tip: Try to build the project.

XML layout :

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <shape
        android:shape="rectangle"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <solid android:color="#ffffff" />

        <corners
            android:bottomLeftRadius="120dp"
            android:bottomRightRadius="120dp"
            android:topLeftRadius="120dp"
            android:topRightRadius="120dp" />

    </shape>
</androidx.constraintlayout.widget.ConstraintLayout>

SOLUTION :

here

Zain
  • 37,492
  • 7
  • 60
  • 84
jujuf1
  • 175
  • 2
  • 10

1 Answers1

3

I think you couldn't see the rounded rectangle as the radii are small so that they might not be noticed, try to set larger values for the four corners

Here is 120dp radii

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">

    <solid android:color="#ffffff" />

    <corners
        android:bottomLeftRadius="120dp"
        android:bottomRightRadius="120dp"
        android:topLeftRadius="120dp"
        android:topRightRadius="120dp" />

</shape>

enter image description here

UPDATE

EDIT 2 : The error is now : The following classes could not be found: - corners (Fix Build Path, Edit XML) - shape (Fix Build Path, Edit XML) - solid (Fix Build Path, Edit XML) Tip: Try to build the project.

You can't use drawable tags into xml layout directly like <shape> or layer-list, instead you can refer to drawable resource with some layout view attributes like android:background as below

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/black">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="@drawable/test"
        android:padding="8dp"
        android:text="Hello World!"
        android:textColor="@android:color/holo_blue_dark"
        android:textSize="22sp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

enter image description here

Zain
  • 37,492
  • 7
  • 60
  • 84
  • Thx. I have already tried this and doesn't work. But I have an error when I build the project : AAPT: error: XML or text declaration not at start of entity. – jujuf1 Dec 25 '20 at 18:49
  • @jujuf1 that could have more than one [reason](https://stackoverflow.com/questions/6474741/error-error-parsing-xml-xml-or-text-declaration-not-at-start-of-entity), but I don't think the provided drawable can do something with that .. can you provide your xml and if you have some java/kotlin behavior to share – Zain Dec 25 '20 at 18:54
  • I have an error into the xml layout. Error is : The following classes could not be found: - corners (Fix Build Path, Edit XML) - shape (Fix Build Path, Edit XML) - solid (Fix Build Path, Edit XML) Tip: Try to build the project. – jujuf1 Dec 25 '20 at 18:59
  • Thx for your reply but if you refer to the stackoverflow question link that i have post, the developpers manage to does work that. I don't undestand – jujuf1 Dec 25 '20 at 19:18