我刚刚用导航抽屉启动了新的android项目,在清单中我发现有两个android:theme。一个内部应用程序标记和一个内部活动。我的问题是,为什么我可以在一个应用程序中有多个主题,而我的应用程序正在使用一个主题。
androidmanifest.xml文件

    <?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.matija.ttestzbrisi">

    <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>
    </application>

</manifest>

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="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" />

最佳答案

android:theme元素中的<application>设置所有活动的默认主题。单个活动可以通过在其android:theme元素中拥有自己的<activity>属性来覆盖此默认值。
为什么我可以在一个应用程序中有多个主题
不是所有的活动都有相同的主题。例如,有些可能使用操作栏,而另一些则不使用。或者,大多数可能是全屏活动,但其他的主题可能更像对话框,而不是占据全屏。

10-07 19:03
查看更多