0

I am getting the following error

You need to use a Theme.AppCompat theme (or descendant) with this activity

I am following a PluralSight course and I think I missed a crucial step somewhere, but after two days of scratching my head, I can't seem to find the obvious.

Here's my code

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
          android:versionCode="1"
          android:versionName="1.0"
          package="com.companyname.bethanypieshopmobile"
          android:installLocation="auto">
    <uses-sdk android:minSdkVersion="21" android:targetSdkVersion="28" />
    <application android:allowBackup="true" 
               android:icon="@mipmap/ic_launcher" 
               android:label="@string/app_name" 
               android:roundIcon="@mipmap/ic_launcher_round" 
               android:supportsRtl="true" 
               android:theme="@style/BethanysTheme"></application>
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.CALL_PHONE" />
</manifest>

Activity.cs

using Android.App;
using Android.OS;
using Android.Support.V4.View;
using Android.Support.V7.App;
using BethanyPieShopMobile.Adapters;

namespace BethanyPieShopMobile
{
    [Activity(Label = "PieMenuWithTabsActivity")]
    public class PieMenuWithTabsActivity : AppCompatActivity
    {
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            //the line below throws the error
            SetContentView(Resource.Layout.pie_menu_tabs);
            var viewPager = FindViewById<ViewPager>(Resource.Id.piePager);
            var categoryFragmentAdapter = new CategoryFragmentAdapter(SupportFragmentManager);
            viewPager.Adapter = categoryFragmentAdapter;
        }
    }
}

styles.xml

<resources>

  <!-- Base application theme. -->
  <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
  </style>

  <style name="BethanysTheme" parent="android:Theme.Material.Light">
    <item name="android:colorPrimary">@color/bethanyGreen</item>
    <item name="android:colorAccent">@color/bethanyBeige</item>
  </style>

  <style name="BethanyGreenText" parent="TextAppearance.AppCompat">
    <item name="android:textColor">#23cfa7</item>
  </style>

</resources>

layout.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.view.ViewPager
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/piePager" >

    <android.support.v4.view.PagerTabStrip
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="top"
        android:paddingBottom="12dp"
        android:paddingTop="10dp"
        android:textColor="#000000"/>

</android.support.v4.view.ViewPager>
PBG
  • 8,944
  • 7
  • 34
  • 48

1 Answers1

0

add theme attribute to MainActivity

[Activity(Label = "", MainLauncher = true, Theme = "@style/AppTheme")]

OR

change theme in manifest

android:theme="@style/MainTheme"

OR

in styles.xml set BethanysTheme's parent="Theme.AppCompat.Light.NoActionBar"

these links will help you