简体   繁体   English

所选活动模板需要现有的应用程序主题

[英]Selected activity template requires an existing Application Theme

I'm learning Android (using Android Studio 2.1.1). 我正在学习Android(使用Android Studio 2.1.1)。

I have created a project with an application module "app" and a library module "mylibrary". 我创建了一个带有应用程序模块“ app”和库模块“ 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. 我可以向app模块添加一个基本活动,并从main活动中调用它,但是在mylibrary模块上,我只能创建“空白”活动。 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. 这只是一个最小的hello-world应用程序,几乎没有我编写的代码,我只是感到困惑,为什么Android不允许我向库模块添加活动,因为它可以在app模块上运行。

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 在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 在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) 设置应用程序的主题(在AndroidManifest.xml中)

        android:theme="@style/AppTheme"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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