C# + Xamarin開發Android應用程式 --- Tab的實現

黄舟
發布: 2017-03-01 10:33:56
原創
1870 人瀏覽過

Layout:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/tabhost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp">
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" />
    </LinearLayout>
</TabHost>
登入後複製

Activity (要從TabActivity繼承):

建立CreateTab方法

private void CreateTab(Type activityType, string tag, string label, int drawableId)
        {
            var intent = new Intent(this, activityType);
            intent.AddFlags(ActivityFlags.NewTask);


            var spec = TabHost.NewTabSpec(tag);
            var drawableIcon = Resources.GetDrawable(drawableId);
            spec.SetIndicator(label, drawableIcon);
            spec.SetContent(intent);


            TabHost.AddTab(spec);
        }
登入後複製

建立兩個Tab

 CreateTab(typeof(BusinessSearch), "Search", "Search", Resource.Drawable.abc_ab_share_pack_mtrl_alpha);
            CreateTab(typeof(MyOrders), "My Orders", "My Orders", Resource.Drawable.abc_btn_check_material);
登入後複製

 以上是C# + Xamarin開發Android應用程式--- Tab的實現的內容,更多相關內容請關注PHP中文網(www.php.cn)!


#
相關標籤:
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!