简体   繁体   中英

Selected activity template requires an existing Application Theme

I'm learning Android (using Android Studio 2.1.1).

I have created a project with an application module "app" and a library module "mylibrary".

I can add a basic activity to the app module and call it from the main activity, however on the mylibrary module, I can only create a "blank" activity. Whenever I try to add a "basic activity" I get the error:

"Selected activity template requires an existing Application Theme"

Why can't I add a basic activity to the library module?

--- EDIT ----

This is just an minimal hello-world application, almost no code written by me, I'm just confused why Android won't let me add an activity to a library module, since it works on the app module.

style.xml

<!-- 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="AppTheme.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />

<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

manifest:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:theme="@style/AppTheme.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name=".LibMainActivity" />
    <!--
 ATTENTION: This was auto-generated to add Google Play services to your project for
 App Indexing.  See https://g.co/AppIndexing/AndroidStudio for more information.
    -->
    <meta-data
        android:name="com.google.android.gms.version"
        android:value="@integer/google_play_services_version" />

    <activity
        android:name=".BasicActivity"
        android:label="@string/title_activity_basic"
        android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

Try this :

In values/styles.xml

  <style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccentRed</item>
  </style>

In v21/styles.xml

 <style name="AppTheme" parent="AppTheme.Base">
    <item name="android:colorPrimary">@color/colorPrimary</item>
    <item name="android:colorAccent">@color/colorAccentRed</item>
    <item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
</style>

Set the theme of your Application (in your AndroidManifest.xml)

        android:theme="@style/AppTheme"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM