Xamarin Android: Cannot use ActionBar.Tab

2.1k views Asked by At

I am stuck at this point where I want to display two tabs below toolbar as in Google Play app enter image description here

Below is the code I used in Xamarin written in C# and using Parse.com backend.

    [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);
    }
}

}

Problem is:
1) The app throws an exception on launching this activity but it compiles and installs on my android device (API 22,Android LOLLIPOP).
2) After compiling it gives me a warning saying "ActionBar.NavigationMode is obsolete" and I don't know what that means.!

Please help,Thanks

    <?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>

This is my layout for screen

1

There are 1 answers

3
Bhavin Kevadiya On

use ViewPager and PagerTabStrip for xml

follow the link fro Example :- 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" />