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的實現的內容,更多相關內容請關注topic.alibabacloud.com(www.php.cn)!