0

I cannot set the BorderColor attribute to my Button. I'm not sure what I'm doing wrong, but Visual Studio says that the attribute was not declared. Android:BorderColor doesn't work either.

The 'BorderColor' attribute is not declared

My code :

<?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"
    android:background="@color/white">
    <TextView
        android:id="@+id/header"
        android:text="@string/header"
        style="@style/header_text" />
    <Button
        android:id="@+id/phones_button"
        android:layout_below="@id/header"
        android:layout_alignParentStart="true"
        android:layout_height="100dp"
        android:layout_width="150dp"
        android:textColor="@color/gray"
        android:background="@color/white"
        BorderColor="@color/gray"
        android:text="@string/phones"
        style="@style/button_style" />
</RelativeLayout>
TylerH
  • 20,799
  • 66
  • 75
  • 101
ls-dev
  • 3
  • 5

2 Answers2

0

The 'BorderColor' attribute is not declared

The problem is IntelliSense could not pick up the attributes we type although those attributes are existing in Android SDK and show that the corresponding Attribute is not declared.

These are occurred due to missing of some .xsd files from XML schema folder in Visual Studio.

To fix this issue, download these files links given below :

You can download and move these file manually to :

C:\Program Files (x86)\Microsoft Visual Studio 14.0\XML\Schemas

or

C:\Program Files (x86)\Microsoft Visual Studio 14.0\XML\Schemas\1033 
TylerH
  • 20,799
  • 66
  • 75
  • 101
Yksh
  • 3,276
  • 10
  • 56
  • 101
  • Hmm this solution looks like the better one, but it doesn't work for me. Are there any other .xsd files that might be missing? – ls-dev Dec 22 '17 at 09:39
0

I cannot set the BorderColor attribute to my Button.

You could refer to @Konstantin Burov's answer, set a shape drawable (a rectangle) as background for your Button.

<Button
    android:id="@+id/my_button"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    android:textColor="@color/grey"
    android:layout_margin="30dp"
    android:background="@drawable/Button_Border"
    />

Create a rectangle drawable Button_Border.xml and put in in Resource/Drawable folder :

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
   android:shape="rectangle" >
    <solid android:color="@android:color/white" />
    <stroke android:width="1dp" android:color="#FF4081"/>
</shape>

Effect :

enter image description here

Update :

This is not a workaround, it' an answer, and there's no BorderColor attribute in Android. Please note that :

Most Android views have attributes in the Android namespace. When referencing these attributes you must include the namespace prefix, or your attribute will be interpreted by aapt as just a custom attribute.

That's why it didn't work, and that's the reason your can deploy this project to your device with no error.

Community
  • 1
  • 1
York Shen
  • 9,014
  • 1
  • 16
  • 40
  • This one works for me. Thanks, but it looks more like a workaround. I can't imagine that there is no other way to set the border of a button. – ls-dev Dec 22 '17 at 09:42