【发布时间】:2019-09-16 01:47:04
【问题描述】:
我的 Splash 活动不会改变,只有当我将名称更改为另一个时才会改变。
例如: "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>
编辑:和我一样的问题: Splash Theme is not changing anymore
编辑 2: 我在一个线程中问了一个问题,以了解我的代码中发生了什么,经过一段时间的坐立不安后,我没有在互联网上找到与 walks 相关的内容。
已经尝试清除缓存,重新创建应用程序,清除文件缓存,已经在 android studio 中完成了所有操作。
过了一会儿,我发现有话要重启应用程序,但似乎会发生变化。
但我不希望用户安装我的应用程序时必须重新启动应用程序才能显示主题中的更改。我该如何解决这个问题?
【问题讨论】:
-
尝试从 AndroidStudio 中禁用
Instant Run -
我已停用,但只有重启手机才能生效
-
您使用的是哪款手机或模拟器?
标签: java android android-studio android-styles