2018년 2월 6일 화요일

[자마린실습예시] Xamarin.Android 인텐트 이용 웹페이지 간단히 오픈하기

(자마린교육)Xamarin.Android 인텐트 이용 웹페이지 간단히 오픈하기

n  “OpenWebpage“ 라는 이름의 Xamarin.Android 프로젝트 생성
n  Resource\layout\Main.axml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
<Button 
    android:id="@+id/myButton"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello"
    />
</LinearLayout>

n  Resource\values\Strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <string name="hello">Go! OracleJava Community</string>
    <string name="app_name">OpenWebpage</string>
</resources>

n  MainActivity.cs 파일에 Button의 클릭 이벤트 코드 작성


using System;

using Android.App;
using Android.Content;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;

namespace OpenWebpage
{
    [Activity (Label = "OpenWebpage", MainLauncher = true)]
    public class MainActivity : Activity
    {

        protected override void OnCreate (Bundle bundle)
        {
            base.OnCreate (bundle);

            // Set our view from the "main" layout resource
            SetContentView (Resource.Layout.Main);

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById<Button> (Resource.Id.myButton);
           
            button.Click += (sender, e) => {
               
                var uri = Android.Net.Uri.Parse ("http://ojc.asia");
                var intent = new Intent (Intent.ActionView, uri); 
                StartActivity (intent);
            };
        }
    }
}

댓글 없음:

댓글 쓰기