【发布时间】:2015-06-18 17:13:22
【问题描述】:
我想在工具栏下方显示两个选项卡,就像在 Google Play 应用程序中一样
以下是我在 Xamarin 中使用 C# 编写并使用 Parse.com 后端的代码。
[Activity (Label = "Home")]
public class Home : Activity
{
ImageView phone;
Toolbar toolbar;
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
ActionBar.NavigationMode = ActionBarNavigationMode.Tabs;
SetContentView (Resource.Layout.Home);
toolbar = FindViewById<Toolbar> (Resource.Id.toolbar1);
SetActionBar(toolbar);
phone = FindViewById<ImageView> (Resource.Id.phonebutton);
ActionBar.Title= "Welcome "+ ParseUser.CurrentUser.Get<String>("Name");
ActionBar.Show ();
ActionBar.Tab tab = ActionBar.NewTab ();
tab.SetText ("Tab 1");
tab.TabSelected += (sender, e) => {Toast.MakeText(this,"Tab1 selected",ToastLength.Long).Show();};
ActionBar.AddTab (tab);
ActionBar.Tab tab2 = ActionBar.NewTab ();
tab.SetText ("Tab 2");
tab.TabSelected += (sender, e) => {Toast.MakeText(this,"Tab2 selected",ToastLength.Long).Show();};
ActionBar.AddTab (tab);
//Responding phonebutton click
phone.Click += Phone_Click;
}
void Phone_Click (object sender, EventArgs e)
{
var num = Android.Net.Uri.Parse ("tel:1234567891");
Intent call = new Intent (Intent.ActionDial,num);
StartActivity (call);
}
}
}
问题是:
1) 该应用程序在启动此活动时引发异常,但它会编译并安装在我的 Android 设备(API 22,Android LOLLIPOP)上。
2)编译后给我一个警告说“ActionBar.NavigationMode 已过时”,我不知道这是什么意思。!
请帮忙,谢谢
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res /android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#cfd8dc"
android:minWidth="25px"
android:minHeight="25px">
<Toolbar
android:minHeight="50dp"
android:background="#90a4ae"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/toolbar1"
android:theme="@style/StatusBarThemed" />
<ImageView
android:src="@drawable/phone"
android:layout_width="93.3dp"
android:layout_height="52.2dp"
android:id="@+id/phonebutton"
android:clickable="true"
android:scaleType="center"
android:layout_alignParentRight="true" />
</RelativeLayout>
这是我的屏幕布局
【问题讨论】:
标签: android xamarin xamarin.android android-tabs