Everytime I create an Android Layout file in Visual Studio (for Xamarin.Android), it gives me a simple layout with a LinearLayout and sets the default namespace of Views to android
. With time, I found it tiresome and repetitive to write the whole android
namespace for every View's properties and started to switch it to simply "x", which I was used to when writing some UWP apps (for example, I write x:id="@+id/SomeId"
instead of android:id="@+id/SomeId
). Still, I have to make this change every time I create a new layout file, so I'd like to know how can I modify this file template (and any other if it's the same process) so that it'll set the default namespace for Views to "x" instead of "android".
Asked
Active
Viewed 33 times
0

Washington A. Ramos
- 874
- 1
- 8
- 25
1 Answers
0
You could change the android
to x
in your layout.
Change:
xmlns:android="http://schemas.android.com/apk/res/android"
To:
xmlns:x="http://schemas.android.com/apk/res/android"
Xaml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:x="http://schemas.android.com/apk/res/android"
x:orientation="vertical"
x:layout_width="match_parent"
x:layout_height="match_parent">
<Button
x:layout_width="match_parent"
x:layout_height="wrap_content"/>
</LinearLayout>

Wendy Zang - MSFT
- 10,509
- 1
- 7
- 17
-
This is what I do every time, what I want to change is the template itself so that each time I use it it already has `xmlns:x="http://schemas.android.com/apk/res/android"` instead of `xmlns:android="http://schemas.android.com/apk/res/android"` – Washington A. Ramos Jan 24 '20 at 06:06
-
As i know, we could not do that with a template. We could change it in each layout. – Wendy Zang - MSFT Jan 28 '20 at 09:12