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

A theme must be used. When attempting to start an Android application, a typical error message shows the AppCompat theme (or descendant) with this activity. 

The activity of the program must utilize a specified theme, as mandated by the Android operating system, which leads to this problem.

What causes the ​error?

 The AppCompat theme is part of the android support library. compatible with older versions of android. If you are using a different theme, your application may not run correctly on older devices.

How to fix the error ?

You need to ensure that the application's main activity is using a Theme. Appcompat theme at its parent theme.

Step #1: Open the AndroidManifest.xml file

Step #2: Locate the main activity for your application.

 <activity android:name=".MainActivity">

    <intent-filter>

      <action android:name="android.intent.action.MAIN" />

      <category android:name="android.intent.category.LAUNCHER" />

    </intent-filter>

 </activity>

Step #3: Add the theme to the main activity. To add a theme to the main activity.

Step #4: Restart the application and you will find that the error has been fixed.In project set Theme.AppCompat.Light or Theme.AppCompat.Light.DarkActtionBar.

  android:theme=”@style/Theme.AppCompat”

Step #5: Change the theme in the themes.xml file

 <resources xmlns:tools="http://schemas.android.com/tools">

    <!-- Base application theme. -->

    <style name="Theme.demo"

     parent="Theme.MaterialComponents.DayNight.NoActionBar">

        <!-- Primary brand color. -->

        <item name="colorPrimary">@color/orange_500</item>

        <item name="colorPrimaryVariant">@color/orange_700</item>

        <item name="colorOnPrimary">@color/white</item>

        <!-- Secondary brand color. -->

        <item name="colorSecondary">@color/teal_200</item>

        <item name="colorSecondaryVariant">@color/teal_700</item>

        <item name="colorOnSecondary">@color/black</item>

        <!-- Status bar color. -->

        <item name="android:statusBarColor" tools:targetApi="l">

       ?attr/colorPrimaryVariant</item>

    </style>

 </resources>

Happy coding!



365Bloggy May 22, 2024
Share this post
Tags
SUBSCRIBE THIS FORM


Archive