我刚刚完成了这个演练,一切都很好,但我的标签上没有图标。 Walkthrough我有手机用android 4.4。有可能android 4.4不再使用TabHost吗?
一些代码。
主要cs文件
namespace com.xamarin.example.tabhostwalkthrough
{
using System;
using Android.App;
using Android.Content;
using Android.Graphics.Drawables;
using Android.OS;
using Android.Widget;
[Activity(Label = "@string/app_name", MainLauncher = true, Icon = "@drawable/ic_launcher")]
public class TabHostWalkthrough : TabActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
CreateTab(typeof(WhatsOnActivity), "whats_on", "What's On", Resource.Drawable.ic_tab_whats_on);
CreateTab(typeof(SpeakersActivity), "speakers", "Speakers", Resource.Drawable.ic_tab_speakers);
CreateTab(typeof(SessionsActivity), "sessions", "Sessions", Resource.Drawable.ic_tab_sessions);
CreateTab(typeof(MyScheduleActivity), "my_schedule", "My Schedule", Resource.Drawable.ic_tab_my_schedule);
}
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 xml文件
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/ic_tab_my_schedule_selected" android:state_selected="true"/>
<item android:drawable="@drawable/ic_tab_my_schedule_unselected"/>
.axml文件到主cs文件
<?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>