【问题标题】:Xamarin Android: Cannot use ActionBar.TabXamarin Android:无法使用 ActionBar.Tab
【发布时间】: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


    【解决方案1】:

    为 xml 使用 ViewPager 和 PagerTabStrip

    点击示例中的链接:- http://www.androidbegin.com/tutorial/android-viewpagertabstrip-fragments-tutorial/

    <android.support.v4.view.PagerTabStrip
        android:id="@+id/english_pager_header"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:paddingBottom="4dp"
        android:paddingTop="4dp"
        android:textColor="#bb343c" />
    

    【讨论】:

    • 从哪里可以下载 Xamarin 上 .v4.View.PagerTabStrip 的支持库。我尝试通过组件添加,但它给了我解压失败的错误 @BhavinKevadiya
    • 我正在使用 C# 和 Xamarin
    • 我创建的标签没有占据它们可用的整个宽度。我怎样才能拉伸它们以使两侧不留空白?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多