ActionBar.Tab,ActionBar.ITabListener此类在此Android平台中已过时

时间:2017-03-17 15:18:40

标签: android xamarin android-actionbar

ActionBar.Tab,ActionBar.ITabListener此类在此Android平台中已废弃,此类都已废弃。

我怎么知道哪个班级是新的?

2 个答案:

答案 0 :(得分:0)

您可以使用Tablayout

使用代码:

 TabLayout tabLayout = ...;
 tabLayout.addTab(tabLayout.newTab().setText("Tab 1"));
 tabLayout.addTab(tabLayout.newTab().setText("Tab 2"));
 tabLayout.addTab(tabLayout.newTab().setText("Tab 3"));
在XMl中

 <android.support.design.widget.TabLayout
         android:layout_height="wrap_content"
         android:layout_width="match_parent">

     <android.support.design.widget.TabItem
             android:text="@string/tab_text"/>

     <android.support.design.widget.TabItem
             android:icon="@drawable/ic_android"/>

 </android.support.design.widget.TabLayout>

以下是示例Link

答案 1 :(得分:0)

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
            xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
 <android.support.v7.widget.Toolbar
   android:id="@+id/toolbar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:layout_alignParentTop="true"
   android:background="?attr/colorPrimary"
   android:elevation="6dp"
   android:minHeight="?attr/actionBarSize"
   android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
   app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>
<LinearLayout
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:id="@+id/main_content"
  android:layout_below="@id/toolbar">
<android.support.design.widget.TabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content"
local:tabMode="scrollable" />
<android.support.v4.view.ViewPager
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="0px"
    android:layout_weight="1"
    android:background="@android:color/white" />
</LinearLayout>
</RelativeLayout>

和main.axml

 <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
using MyTabLayout = Android.Support.Design.Widget.TabLayout;

 [Activity(Label = "TabLayout", Theme = "@style/AppTheme", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
    protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

         SetContentView (Resource.Layout.Main);


        var tabLayout = FindViewById<MyTabLayout>(Resource.Id.sliding_tabs);
        tabLayout.AddTab(tabLayout.NewTab().SetText("Tab 1"));
        tabLayout.AddTab(tabLayout.NewTab().SetText("Tab 2"));
        tabLayout.AddTab(tabLayout.NewTab().SetText("Tab 3"));
        tabLayout.TabGravity = MyTabLayout.GravityFill;

    }
}