Hello,
Welcome to our Microsoft Q&A platform!
This is not a real use case, but for simplicity i want to create a button in an Android Class Library to be able to use that button in several Xamarin solution.
I have seen that, when creating a Mobile App (Xamarin.Forms) solution it has an android project and an Xamarin forms project. The android project has a layout folder with some page designs. Instead of designing a whole page through the use of layouts, is it possible to only describe the design of a single button, in one of those layout xml files?
Do you want to create a new button and use the button in several pages's layout , right?
If yes, you can use define a xml( MyButton.xml
) in folder layout
and include it in other page's layout .
You can refer to the following code:
MyButton.xml
<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mBtn"
android:layout_width="200dp"
android:layout_height="50dp"
android:text="my button"
android:textColor="@android:color/holo_red_dark"
android:background="@android:color/holo_orange_light"
>
</Button>
And include above button on other page's layout:
<?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">
<include
layout="@layout/mybutton"/>
</LinearLayout>
Best Regards,
Jessie Zhang
---
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.