Android 清单 app:theme
Android Manifest app:theme
我刚开始新的 android 项目,导航 Drawer.Looking 到清单中,我发现有两个 android:theme。一个在应用程序标签内,一个在 activity 内。我的问题是为什么我可以在一个应用程序中有多个主题,并且 我的应用程序正在使用一个主题。
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" />
<application>
元素中的 android:theme
设置所有活动的默认主题。个别活动可以通过在其 <activity>
元素中拥有自己的 android:theme
属性来覆盖此默认值。
how come i can have multiple themes inside one application
并非所有活动都有相同的主题。例如,一些人可能会使用操作栏,而另一些人则不会。或者,大多数活动可能是全屏活动,但其他活动的主题可能更像是对话框,而不是全屏。
应用程序的主题将对整个应用程序通用,这是很明显的。但是 android 为您提供了为您的活动单独设置主题的功能。例如,在您的应用程序中,您的 MainActivity 没有 ActionBar。但是你可以在你的应用程序中创建新的活动,它可能有一个带有浅色或深色主题的 ActionBar,或者你选择的任何自定义主题。
我希望这能回答你的问题。
您可以使用 <activity>
元素中的 android:theme 属性自定义主题 activity。如果不提供任何主题,它将使用应用程序明智的主题 activity。
希望它能清除更多。
我刚开始新的 android 项目,导航 Drawer.Looking 到清单中,我发现有两个 android:theme。一个在应用程序标签内,一个在 activity 内。我的问题是为什么我可以在一个应用程序中有多个主题,并且 我的应用程序正在使用一个主题。
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" />
<application>
元素中的 android:theme
设置所有活动的默认主题。个别活动可以通过在其 <activity>
元素中拥有自己的 android:theme
属性来覆盖此默认值。
how come i can have multiple themes inside one application
并非所有活动都有相同的主题。例如,一些人可能会使用操作栏,而另一些人则不会。或者,大多数活动可能是全屏活动,但其他活动的主题可能更像是对话框,而不是全屏。
应用程序的主题将对整个应用程序通用,这是很明显的。但是 android 为您提供了为您的活动单独设置主题的功能。例如,在您的应用程序中,您的 MainActivity 没有 ActionBar。但是你可以在你的应用程序中创建新的活动,它可能有一个带有浅色或深色主题的 ActionBar,或者你选择的任何自定义主题。
我希望这能回答你的问题。
您可以使用 <activity>
元素中的 android:theme 属性自定义主题 activity。如果不提供任何主题,它将使用应用程序明智的主题 activity。
希望它能清除更多。