活动主题未更改

问题描述 投票:5回答:4

我的飞溅活动没有改变,只有在我将名称更改为另一个时,它才会改变。

例如:“ SplashActivity”-从修改开始

如果将主题更改为另一种颜色,则需要将该活动重命名为:“ SplashActivityy”或其他名称。

如果我返回到名称“ SplashActivity”,则修改将返回到以后。

已经格式化并清除了android studio的缓存,这没有帮助!

AndroidManifest.xml

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

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme"
        android:name=".App"
        tools:ignore="GoogleAppIndexingWarning">
        <activity
            android:name=".SplashActivity"
            android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAINACTIVITY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>

SplashActivity.java

package com.example.cobaiascreen;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.view.WindowManager;

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //Hiding Title bar of this activity screen */
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
        //Making this activity, full screen */
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}

App.java

package com.example.cobaiascreen;

import android.app.Application;
import android.os.SystemClock;

import java.util.concurrent.TimeUnit;

public class App extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        // Don't do this! This is just so cold launches take some time
        SystemClock.sleep(TimeUnit.SECONDS.toMillis(3));
    }
}

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="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/background_splash</item>
    </style>

</resources>

background_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

    <item
        android:drawable="@color/colorPrimaryDark"/>

    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/icon"/>
    </item>

</layer-list>

EDIT:和我的问题一样:Splash Theme is not changing anymore

编辑2:经过一阵烦躁,我没有在网上找到与之相关的散步,我问了一个线程问题,以了解我的代码中发生了什么。

已经尝试清除缓存,重新创​​建应用程序,清除文件缓存,已经在android studio中进行了所有操作。

过了一会儿,我发现正在谈论重启应用程序的事情,看起来似乎有所变化。

但是我不希望用户安装我的应用程序而必须重新启动应用程序以显示主题更改。我该如何解决这个问题?

java android android-studio android-styles
4个回答
6
投票

当我深入分析代码时,我没有发现代码中出现“您在说什么”的原因。因此,根据我的原因可能是:

也许that您有多个可绘制文件夹,并且文件[[background_splash.xml存在于您的设备特定的可绘制文件夹中,该文件夹可能是drawable-xxhdpi中的drawable and]] ]&很有可能您正在drawable中进行与设备无关的更改。

因此,请进行验证,样式也相同(如果适用)。

您可以采取的其他措施是

    禁用即时运行。

  • [C0之后,卸载应用程序,然后delete data从应用程序信息>手机的存储选项,然后重新安装。
  • 希望以上任何一种技术都能为您服务。
  • 尝试一下:

    clear cache

    您确定<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="windowActionBar">false</item>
        <item name="android:windowBackground">@drawable/background_splash</item>
    </style>
    存在吗?

    Android Studio的增量构建系统“ Instant Run”存在问题。这就是为什么他们根据项目Marble引入了新的/改进的增量构建,称为“应用更改”。在Android Studio版本3.5中可用。请参阅文档android.intent.action.MAINACTIVITY

    尝试将here更改为android:allowBackup="true"。安装应用程序。然后完全卸载它。重新安装。看一下主题。然后更改主题并重新安装-检查主题是否已更改。

    1
    投票
    尝试一下:

    1
    投票
    Android Studio的增量构建系统“ Instant Run”存在问题。这就是为什么他们根据项目Marble引入了新的/改进的增量构建,称为“应用更改”。在Android Studio版本3.5中可用。请参阅文档android.intent.action.MAINACTIVITY

    1
    投票
    尝试将here更改为android:allowBackup="true"。安装应用程序。然后完全卸载它。重新安装。看一下主题。然后更改主题并重新安装-检查主题是否已更改。
    © www.soinside.com 2019 - 2024. All rights reserved.