0
Main.axml
xamarin androidにアクションバータブを作成するには?
で
<?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">
<FrameLayout
android:id="@+id/fragmentContainer"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1" />
</LinearLayout>
そしてMainActivity.cs
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 += delegate { button.Text = string.Format("{0} clicks!", count++); };
// enable navigation mode to support tab layout
this.ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
//adding genres tab
AddTab("Genres", new GenresFragment());
//adding music tab
AddTab("Music", new MusicFragment());
//
}
/*
tabText:title to be displayed in tab
iconResourceId: image/source id
fragment:fragment reference
*/
void AddTab(string tabText, Fragment fragment)
{
var tab = this.ActionBar.NewTab();
tab.SetText(tabText);
// if using icon-> tab.SetIcon(iconResourceId)
//must set event handler for replacing tabs tab
tab.TabReselected += delegate (object sender, ActionBar.TabEventArgs e)
{
e.FragmentTransaction.Replace(Resource.Id.fragmentContainer, fragment);
};
this.ActionBar.AddTab(tab);
}
最初に、私は** Resource.Id.fragmentContainerがfragmentContainerの定義が含まれていないという問題を得ました。 **。
私はxamarin(visual studio 2015)の新しい開発者です。ですから、みんながこの問題を解決するのを助けてください。
私が作成したタブは、利用可能な幅全体を占めていません。どのように私は両側に空きスペースが残らないようにそれらを伸ばすことができますか? –