Plumorane
Plumorane

Reputation: 31

XML Code for new button is not working

I am trying to make a new button for my android application.

I created a new XML file in my drawable folder that has the following code:

 `<?xml version="1.0" encoding="utf-8"?>
  <shape xmlns:android="http://schemas.android.com/apk/res/android" 
   android:shape="rectangle" >
   <corners
   android:radius="12dp"
    />
  <solid
    android:color="#00000000"
    />
  <padding
    android:left="0dp"
    android:top="0dp"
    android:right="0dp"
    android:bottom="0dp"
    />
 <size
    android:width="270dp"
    android:height="60dp"
    />
<stroke
    android:width="3dp"
    android:color="#FFFFFF"
    />
 </shape>

Then I tried to call it using the following code:

<Button
 android:id="@+id/newBtton"

 android:text="Get Started"
 android:textColor="#FFFFFF"
 android:textSize="30sp"

 android:layout_width="270dp"
 android:layout_height="60dp"
 android:background="@drawable/buttonshape"
 />

However this does not work. Even in the preview of my XML file it just gives me a blank immage

When I try to validate my XML file I get the following error: Error:(2, 94) cvc-elt.1.a: Cannot find the declaration of element 'shape'. Error:(1, 56) s4s-elt-schema-ns: The namespace of element 'x' must be from the schema namespace, 'http://www.w3.org/2001/XMLSchema'. Error:(1, 56) s4s-elt-invalid: Element 'x' is not a valid element in a schema document. Error:(1, 56) schema_reference.4: Failed to read schema document 'null', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not .

I was just wondering how I would fix this error or what I was doing wrong?

Also I am working in android studio

Upvotes: 2

Views: 619

Answers (3)

Prudhvi Bsecure
Prudhvi Bsecure

Reputation: 35

**Note : Try this code work for you. in solid tag you can change what color 
        you want.**

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

<solid android:color="@color/transparent_gray" />

 <stroke
    android:width="1dp"
    android:color="#D2D2D2" />

<corners android:radius="15dp" />

<padding
    android:bottom="5dp"
    android:left="5dp"
    android:right="5dp"
    android:top="5dp" />

</shape>

Upvotes: 1

Use this sample

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

<corners
    android:bottomRightRadius="10dp"
    android:radius="40dp" />

<gradient
    android:angle="45"
    android:centerX="float"
    android:centerY="float"
    android:endColor="#01f1fa"
    android:gradientRadius="integer"
    android:startColor="#0189ff"
    android:type="linear" />

<!--If your shape requires only one solid color-->
<!--<solid
    android:color="#FFFFFF" />-->

<size
    android:width="82dp"
    android:height="82dp" />

<!--Use android:dashWidth="2dp" and android:dashGap="2dp"
to add dashes to your stroke-->
<stroke
    android:width="2dp"
    android:color="#FFFFFF" />

<!--If you want to add padding-->
<!-- <padding
     android:left="10dp"
     android:top="20dp"
     android:right="40dp"
     android:bottom="8dp" />-->

Upvotes: 2

devDeejay
devDeejay

Reputation: 6049

Try My Style Of Button And Let Me Know If This Shows Or Not:

<?xml version="1.0" encoding="UTF-8"?>
<shape 
    xmlns:android="http://schemas.android.com/apk/res/android">
    <stroke 
        android:width="1dp" 
        android:color="#505050"/>
    <corners 
        android:radius="7dp" />

    <padding 
        android:left="1dp"
        android:right="1dp"
        android:top="1dp"
        android:bottom="1dp"/>

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

</shape>

Upvotes: 1

Related Questions