【问题标题】:Two styles on two different Activities两种不同活动的两种风格
【发布时间】:2017-01-25 16:42:07
【问题描述】:

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

我的想法是我希望启动屏幕是全屏的,并且所有其他活动都像往常一样有一个标题栏和一个 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 style会改变所有app的Activity,我只想改变一个

任何帮助将不胜感激。

【问题讨论】:

    标签: android android-theme


    【解决方案1】:

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

    <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" 是您想要的,如果您不需要工具栏

    【讨论】:

      【解决方案2】:

      您只需将带有工具栏的样式设置为您想要的每个活动的样式。

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

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

      然后你必须在每个活动中写下你想要的样式:

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

      【讨论】:

      • 我明白了,我试图在活动布局中更改主题,而不是在清单本身中
      猜你喜欢
      • 2015-11-26
      • 2012-02-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      相关资源
      最近更新 更多