简体   繁体   English

活动主题没有改变

[英]Activity Theme is not changing

my Splash activity doesn't change, it only changes if I change the name to another.我的 Splash 活动不会改变,它只会在我将名称更改为另一个时才会改变。

For example: " SplashActivity " - Start with a Modification例如:“ SplashActivity ” - 从修改开始

If I change the theme to another color, I need to rename the activity to: " SplashActivityy " or some other name than it was.如果我将主题更改为另一种颜色,我需要将活动重命名为:“ SplashActivityy ”或其他名称。

If I go back to the name " SplashActivity " the modification goes back to later.如果我回到名称“ SplashActivity ”,则修改将返回到稍后。

Already formatted and cleared cache of android studio, this did not help!已经格式化并清除了android studio的缓存,这没有帮助!

AndroidManifest.xml 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 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应用程序.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 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 : problems just like mine: Splash Theme is not changing anymore编辑:和我一样的问题: 飞溅主题不再改变

EDIT 2: I asked a question in a thread to find out what was going on in my code, after a while fidgeting I didn't find walks on the internet related.编辑 2:我在一个线程中问了一个问题,以了解我的代码中发生了什么,经过一段时间的烦躁,我没有找到与互联网相关的步行。

Already tried to clear cache, recreate the application, cleared the cache of files, already did everything in android studio.已经尝试清除缓存,重新创​​建应用程序,清除文件缓存,已经在android studio中完成了所有操作。

After a while I found something talking to restart the application that would appear to change.过了一会儿,我发现有什么东西可以重新启动似乎发生变化的应用程序。

But I do not want the user to install my application to have to restart the application to appear the changes in the theme.但我不希望用户安装我的应用程序必须重新启动应用程序才能出现主题中的更改。 How can I solve this problem?我怎么解决这个问题?

As i Deeply analysed the code and i found no reason for that "What you are saying" in the code.当我深入分析代码时,我没有发现代码中“你在说什么”的原因。 So what could be a reason according to me is:所以我认为可能的原因是:

Maybe that you have multiple drawable folder and the file background_splash.xml is present in your device specific drawable folder that might be drawable-xxhdpi and also in drawable也许有多个绘制文件夹和文件background_splash.xml出现在你的设备特定文件夹绘制的,可能是drawable-xxhdpi以及drawable

& most probably you are doing change in drawable that don't relates to your device.并且很可能您正在更改与您的设备无关的drawable

So kindly verify it, Same for styles also "if applicable".所以请验证它,对于样式也是“如果适用”。

other measures you can take are您可以采取的其他措施是

  • Make Instant run disable.禁用即时运行。
  • Uninstall the app after delete data and clear cache from app info> storage option of phone and then install again. delete data并从手机的应用信息>存储选项中clear cache后卸载应用,然后重新安装。

Hope any of the above technique will work for you.希望以上任何一种技术都对您有用。

Try this:尝试这个:

<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
    <item name="windowActionBar">false</item>
    <item name="android:windowBackground">@drawable/background_splash</item>
</style>

Are you sure that android.intent.action.MAINACTIVITY exists?您确定android.intent.action.MAINACTIVITY存在吗?

There are issues with the incremental build system "Instant Run" of android studio. android studio 的增量构建系统“Instant Run”存在问题。 This is why they have introduced new/improved incremental build called "Apply Changes" as result of project Marble.这就是为什么他们引入了新的/改进的增量构建,称为“应用更改”作为 Marble 项目的结果。 It is available in android studio version 3.5.它在 android studio 3.5 版中可用。 Please see the documentation here请参阅此处的文档

Try to change android:allowBackup="true" to android:allowBackup="false" .尝试将android:allowBackup="true"更改为android:allowBackup="false" Install the app.安装应用程序。 Then completely deinstall it.然后完全卸载它。 Install it again.重新安装。 Look at the theme.看主题。 Then change the theme and reinstall - check if the theme is changed.然后更改主题并重新安装 - 检查主题是否已更改。

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

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