This is the first post in a few days. I'm a student programmer who is still studying how the app works, but I'll do my best!
I will keep up with you. This screen is quite important when creating an app. It's annoying to come out every time, but I think it's the best way to actually recognize the app name. Smartnews, Gunosy, Twitter, etc ... You will be able to remember the name by displaying this each time you open it. So let's do it right away! !!
Add a new style to res / values / styles.xml. This time, let's call it Splash Theme. First select styles.xml.
styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">#EA5E5D</item>
<item name="colorPrimaryDark">#EA5E5D</item>
<item name="colorAccent">#EA5E5D</item>
</style>
<!--Please copy and paste from here.-->
<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
</style>
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">@mipmap/imageview</item>
</style>
</resources>
Add the style you set earlier.
AndroidManifest.xml
<application
android:allowBackup="true"
android:icon="@mipmap/i_topics_icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/i_topics_icon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<!--Add below from here.-->
<activity android:name=".MainActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<activity android:name=".MainActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
Be sure to add here. Since the splash screen is displayed only once, please prepare a theme separately from the application theme. I had a lot of trouble not doing that lol
MainActivity.java
package android.wings.websarva.com.splash;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Add from here
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
setTheme(R.style.AppTheme);
//So far
setContentView(R.layout.activity_main);
}
}
You can now add it. You can pause the thread for the specified time by using sleep provided by the Thread class. This time I want to stop for 2 seconds, so set thread.sleep (2000).
I think the screen will switch like this.
Articles that I used as a reference https://qiita.com/yamikoo@github/items/c82ea335968709a9d32a It was very easy to understand. Thank you very much.
Recommended Posts