M4theuz
M4theuz

Reputation: 153

Activity Theme is not changing

my Splash activity doesn't change, it only changes if I change the name to another.

For example: "SplashActivity" - Start with a Modification

If I change the theme to another color, I need to rename the activity to: "SplashActivityy" or some other name than it was.

If I go back to the name "SplashActivity" the modification goes back to later.

Already formatted and cleared cache of android studio, this did not help!

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: 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.

Already tried to clear cache, recreate the application, cleared the cache of files, already did everything in 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?

Upvotes: 5

Views: 1704

Answers (4)

Intsab Haider
Intsab Haider

Reputation: 3561

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

& most probably you are doing change in drawable that don't relates to your device.

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.

Hope any of the above technique will work for you.

Upvotes: 6

Pavlo Ostasha
Pavlo Ostasha

Reputation: 16699

Try to change android:allowBackup="true" to 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.

Upvotes: 1

Susheel Tickoo
Susheel Tickoo

Reputation: 547

There are issues with the incremental build system "Instant Run" of android studio. This is why they have introduced new/improved incremental build called "Apply Changes" as result of project Marble. It is available in android studio version 3.5. Please see the documentation here

Upvotes: 1

Yash
Yash

Reputation: 3576

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?

Upvotes: 1

Related Questions