Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import Shape class in XML

How can I import the class android.graphics.drawable.shapes.Shape in XML in Android Studio? I'm getting "Cannot resolve class shape".

<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
</shape>
like image 521
Josh Avatar asked Oct 14 '25 22:10

Josh


2 Answers

I think there aren't any problem in the code. Why don't you check these things.

  1. Did you write the code in res/drawable/something.xml? You have to write your own file name at the something part.
  2. There isn't <?xml version="1.0" encoding="utf-8"?> at the top.
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
</shape>
  1. Do Clean, Rebuild Project.
  2. Do Invalidate Cache/Restart.
like image 119
Isaac Lee Avatar answered Oct 17 '25 14:10

Isaac Lee


right click on the drawable folder then new, select drawable resource file give any file name change that selector to shape and encode the file using UTF-8 like this

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/white" />
like image 42
sumanth.js Avatar answered Oct 17 '25 13:10

sumanth.js