C#Android:错误类不能有多个基类:'Android.Support.V7.App.ActionBarActivity'和'TabHostAct'

时间:2016-04-06 02:18:51

标签: c# android

我正在尝试在一个类中扩展两个活动。我知道这是不可能的,我试图制作两个不同的类:

[Activity(Label = "DLS", Theme = "@style/MyTheme", ScreenOrientation = Android.Content.PM.ScreenOrientation.Portrait)]
public class ActProduct : ActionBarActivity, TabHostAct
{
        base.OnCreate(savedInstanceState);

        // Create your application here
        SetContentView(Resource.Layout.layProduct);

        mToolbar = FindViewById<SupportToolbar>(Resource.Id.toolbar);
        mDrawerLayout = FindViewById<DrawerLayout>(Resource.Id.drawer_layout);
        mLeftDrawer = FindViewById<ListView>(Resource.Id.left_drawer);

        mLeftDrawer.Tag = 0;

        SetSupportActionBar(mToolbar);

        mLeftDataSet = new List<string>();
        mLeftDataSet.Add("Login");
        mLeftDataSet.Add("Camera");
        mLeftDataSet.Add("Maps");
        mLeftDataSet.Add("Product");
        mLeftAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, mLeftDataSet);
        mLeftDrawer.Adapter = mLeftAdapter;
        mLeftDrawer.ItemClick += MenuListView_ItemClick;

        mDrawerToggle = new MyActionBarDrawerToggle(
            this,                           //Host Activity
            mDrawerLayout,                  //DrawerLayout
            Resource.String.openDrawer,     //Opened Message
            Resource.String.closeDrawer     //Closed Message
        );

        mDrawerLayout.SetDrawerListener(mDrawerToggle);
        SupportActionBar.SetHomeButtonEnabled(true);
        SupportActionBar.SetDisplayShowTitleEnabled(true);
        mDrawerToggle.SyncState();
}

public class TabHostAct : TabActivity
{
    protected override void OnCreate(Bundle savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        CreateTab(typeof(ActProProduk), "Prod", "Product", Resource.Drawable.ic_tab_product);
        CreateTab(typeof(ActProCustomer), "Cust", "Customer", Resource.Drawable.ic_tab_customer);
        CreateTab(typeof(ActProPromo), "Promo", "Promotion", Resource.Drawable.ic_tab_promo);
    }

    private void CreateTab(Type activityType, string tag, string label, int drawableId)
    {
        var intent = new Intent(this, activityType);
        intent.AddFlags(ActivityFlags.NewTask);

        var spec = TabHost.NewTabSpec(tag);
        var drawableIcon = Resources.GetDrawable(drawableId);
        spec.SetIndicator(label, drawableIcon);
        spec.SetContent(intent);

        TabHost.AddTab(spec);
    }
}

这是我的.axml布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    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:minHeight="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Dark" />
    <android.support.v4.widget.DrawerLayout
        android:id="@+id/drawer_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    <!-- The Main Content View -->
        <FrameLayout
            android:id="@+id/main"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginRight="25dp"
                android:layout_marginLeft="25dp">
                <TabHost
                    android:id="@android:id/tabhost"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent">
                    <LinearLayout
                        android:orientation="vertical"
                        android:layout_width="fill_parent"
                        android:layout_height="fill_parent"
                        android:padding="5dp">
                        <TabWidget
                            android:id="@android:id/tabs"
                            android:layout_width="fill_parent"
                            android:layout_height="wrap_content" />
                        <FrameLayout
                            android:id="@android:id/tabcontent"
                            android:layout_width="fill_parent"
                            android:layout_height="fill_parent"
                            android:padding="5dp" />
                    </LinearLayout>
                </TabHost>
            </LinearLayout>
        </LinearLayout>
    <!-- The Left Navigation Drawer -->
        <ListView
            android:id="@+id/left_drawer"
            android:layout_width="240dp"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:choiceMode="singleChoice"
            android:divider="#818181"
            android:dividerHeight="1dp"
            android:background="#E3F2FD" />
    </android.support.v4.widget.DrawerLayout>
</LinearLayout>

我的问题有解决办法吗?提前谢谢你。

1 个答案:

答案 0 :(得分:0)

请勿使用TabActivity。相反,在您的布局中包含TabHost