Introduction:
In Xamarin.Android, we can easily make rounded corner EditText with selector we need some simple steps to create xml files in layout resource directory of android application. This article will guide you in details to create rounded corner EditText.
This article can explain you below topics:
In Xamarin.Android, we can easily make rounded corner EditText with selector we need some simple steps to create xml files in layout resource directory of android application. This article will guide you in details to create rounded corner EditText.
Requirements:
- This article source code is prepared by using Visual Studio Community for Mac (7.4). And it is better to install latest visual studio updates from here.
- This sample project is Xamarin.Android project and tested in emulator.
Description:
This article can explain you below topics:
1. Create the new Xamarin.Android project.
2. Adding rounded corner selector layout.
2. Adding rounded corner selector layout.
3. Using rounded corner selector for EditText.
1. Create the new Xamarin.Android project
- Launch Visual Studio for Mac.
- On the File menu, select New Solution.
- The New Project dialog appears. The left pane of the dialog lets you select the type of templates to display. In the left pane, expand Android > App > General > Android App and click on Next.
- Enter your App Name (Ex: RoundedEditText). And click on Next button.
- You can choose your project location like below.
2. Adding rounded corner selector layout.
Right click on layout folder => Add => New File
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape
android:shape="rectangle">
<solid
android:color="#ffffff" />
<corners
android:radius="10dp" />
<stroke
android:width="2dp"
android:color="#3bbdfa" />
</shape>
</item>
</selector>
3. Using rounded corner selector for EditText
Main.axml
Now open Main.axml, create EditText and set background with above layout like below:
Right click on layout folder => Add => New File
Add layout rounded_border_edittext like below:
3. Using rounded corner selector for EditText
Main.axml
Now open Main.axml, create EditText and set background with above layout like below:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@android:color/white">
- <EditText
- android:id="@+id/myEditText"
- android:layout_width="match_parent"
- android:layout_height="55dp"
- android:hint="EditText Rounded Border"
- android:layout_margin="20dp"
- android:padding="5dp"
- android:background="@layout/rounded_border_edittext"
- android:layout_gravity="center" />
- </LinearLayout>
Demo screen from Android:
You can directly work on below sample source code to understand this article.
FeedBack Note: Please share your thoughts, what you think about this post, Is this post really helpful for you? I always welcome if you drop comments on this post and it would be impressive.
No comments:
Post a Comment