Так что я некоторое время застрял, пытаясь реализовать пару вкладок в свой проект. Я немного прочитал, как это сделать, и я не уверен, почему он не работает. Может ли кто-нибудь сказать мне, что я делаю неправильно? Вот мой .csЗакладки Android не работают должным образом. C#
public class TabActivity1 : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.Text = "Tab 1";
SetContentView(textview);
}
}
public class TabActivity2 : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
TextView textview = new TextView(this);
textview.Text = "Tab 2";
SetContentView(textview);
}
}
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
TabHost tab_host = FindViewById<TabHost>(Resource.Id.tabHost);
TabHost.TabSpec spec;
Intent intent;
intent = new Intent(this, typeof(TabActivity1));
intent.AddFlags(ActivityFlags.NewTask);
spec = tab_host.NewTabSpec("Tab 1");
spec.SetIndicator("tab1");
spec.SetContent(intent);
tab_host.AddTab(spec);
intent = new Intent(this, typeof(TabActivity2));
intent.AddFlags(ActivityFlags.NewTask);
spec = tab_host.NewTabSpec("Tab 2");
spec.SetIndicator("tab2");
spec.SetContent(intent);
tab_host.AddTab(spec);
}
}
вот .axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minWidth="25px"
android:minHeight="25px">
<TabHost
android:minWidth="25px"
android:minHeight="25px"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/tabHost">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="@+id/linearLayout1">
<TabWidget
android:id="@android:id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
</TabHost>
</LinearLayout>
Here «s, что приложение выводит.
Я бы очень признателен за любую помощь, которую я могу получить, спасибо!
Итак, каков ожидаемый результат? Очень утомительно угадать желаемый результат, просто взглянув на код. – hankide
Я надеялся на 2 вкладки с надписью tab 1 и tab 2, а на каждой вкладке - текстовое поле, в котором указана вкладка 1 на вкладке 1 и вкладке 2 внутри вкладки 2. Как вы думаете, что я могу сделать для этого? –