Book Image

Learning Xamarin studio

By : William Smith
Book Image

Learning Xamarin studio

By: William Smith

Overview of this book

Table of Contents (16 chapters)
Learning Xamarin Studio
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Creating a Layout in Xamarin Studio


Let's create a Layout using the Xamarin Studio designer:

  1. Create a new Android Application solution named LayoutDemo.

  2. Add a new Android Layout file to the /Resources/layouts folder named MainLayout.

  3. When the designer opens, open the Toolbox pad.

  4. From the Text Fields group, drag a Plain Text object onto your canvas.

  5. From the Form Widgets group, drag a Button object onto your canvas.

  6. Again from the Form Widgets group, drag a Text (Medium) label object onto you canvas.

    Your layout should look something like the following screenshot:

  7. Open the MainActivity.cs file.

  8. Replace the OnCreate() method with the following code:

    protected override void OnCreate (Bundle bundle)
    {
        base.OnCreate (bundle);
        SetContentView (Resource.Layout.MainLayout);
    
        // Get our button from the layout resource,
        // and attach an event to it
        Button button = FindViewById<Button> 
    (Resource.Id.button1);
        TextView textView = FindViewById<TextView> 
    (Resource.Id.textView1...