【问题标题】:Android Manifest app:themeAndroid Manifest 应用程序:主题
【发布时间】:2016-02-11 17:11:01
【问题描述】:

我刚刚使用 Navigation Drawer 启动了新的 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>

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="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 android-manifest android-theme


    【解决方案1】:

    &lt;application&gt; 元素中的android:theme 为您的所有活动设置默认主题。个别活动可以通过在其&lt;activity&gt; 元素中拥有自己的android:theme 属性来覆盖此默认值。

    为什么我可以在一个应用程序中拥有多个主题

    并非所有活动都有相同的主题。例如,有些可能使用操作栏,有些则不使用。或者,大多数活动可能是全屏活动,但其他活动的主题可能更像对话框,而不是全屏。

    【讨论】:

    • 所以基本上在我的活动中我覆盖了我的应用程序主题并在那个主题上我设置了这两个属性 falsetrue
    【解决方案2】:

    应用程序的主题对整个应用程序都是通用的,这很明显。但是 android 为您提供了为您的活动单独设置主题的功能。例如,在您的应用中,您的 MainActivity 没有 ActionBar。但是您可以在您的应用程序中创建新的活动,这些活动可能有一个带有浅色或深色主题的 ActionBar,或者您选择的任何自定义主题。

    我希望这能回答你的问题。

    【讨论】:

      【解决方案3】:

      您可以在 &lt;activity&gt; 元素中使用 android:theme 属性明智地自定义主题活动。如果不提供任何主题,它将为该活动使用应用程序明智的主题。

      希望它会更清楚。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-03-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-12-18
        相关资源
        最近更新 更多