繁体   English   中英

两种不同活动的两种风格

[英]Two styles on two different Activities

我有一个启动画面和其他活动。

这个想法是我希望启动画面是全屏的,并且所有其他活动像往常一样有一个标题栏和一个 ActionBar。

我在styles.xml文件中设置了2个样式

<!-- 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>

<!-- Splash theme. -->
<style name="Splash" parent="@style/Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="android:windowFullscreen">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

然后在清单文件中我放

android:theme="@style/AppTheme"

在那之后,我迷路了:我尝试在xml代码中将样式和/或主题设置为对splashScreen使用“Splash”,但是没有用

设置 manifest 样式改变了所有的应用活动,我只想改变一个

任何帮助,将不胜感激。

更改活动主题,而不是应用程序主题。

<application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:fullBackupContent="false"
        android:label="@string/app_name"
        android:theme="@style/AppTheme"> <!-- Not here -->

    <activity 
        android:name=".SplashActivity"
        android:theme="@style/Splash" /> <!-- Change/add here -->

但请注意: parent="Theme.AppCompat.Light.NoActionBar"如果您不想要 Toolbar,则是您想要的

您只需要使带有工具栏的样式成为您想要的每个活动的样式。

例如,在您的清单文件中,您可以适应全局样式:

<application
    android:theme="@style/AppTheme">

之后,您必须在每个活动中编写您想要的样式:

    <activity
        android:name=".SplashActivity"
        android:theme="@style/Splash">
    </activity>

暂无
暂无

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

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