728x90
λͺ¨λ°μΌ μ±μμ Splash Screen μ΄λ?
- μ΄λ€ μ΄ν리μΌμ΄μ μ΄ μ€νλλ©΄μ κ°μ₯ μ²μμ λ¨λ νλ©΄μ΄λ€.
- νκ΅μΈμ΄ λͺ¨λ μ¬μ©νλ μΉ΄μΉ΄μ€ν‘μ μλ‘ λ€μλ©΄, μΉ΄μΉ΄μ€ν‘ μ΄νμ μΌ€ λ κ°μ₯ μ²μμ λ¨λ λ Έλμ νλ©΄μ λ§νλ€.
- λ³΄ν΅ μ΄κΈ°ν μμ μ νκ±°λ λ²μ μ 보 νκΈ° λ±μ μ¬μ©νλ€.
1. activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="MainActivity"
android:textStyle="bold"
android:textSize="35dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
2. activity_splash.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Splash Screen"
android:textStyle="bold"
android:textSize="35dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
3. AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.devshin93.splashexample">
<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/Theme.SplashExample">
<activity android:name=".MainActivity"> </activity>
<activity android:name=".SplashActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
4. MainActivity.java
package com.devshin93.splashexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
5. SplashActivity.java
package com.devshin93.splashexample;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.view.Window;
import androidx.appcompat.app.AppCompatActivity;
public class SplashActivity extends AppCompatActivity implements View.OnClickListener {
private Handler handler;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide(); // actionBar μ¨κΈ°κΈ°
setContentView(R.layout.activity_splash);
handler = new Handler(Looper.getMainLooper());
}
@Override
protected void onStart() {
super.onStart();
// Splash Screen νλ©΄μ΄ μμλκ³ , λλ μ΄λ₯Ό μ€ νμ run() μμ μ½λλ₯Ό λμνλ€.
// 1s = 1000ms
handler.postDelayed(new Runnable() {
@Override
public void run() {
SplashActivity.this.beginMainActivity();
}
}, 2000); // 2μ΄ λ€μ run() μμ λμμ ν¨
}
@Override
public void onClick(View view) {
// Splash Screen νλ©΄μ΄ ν΄λ¦λλ©΄ λ°λ‘ MainActivity λ₯Ό μ€ννλ€.
beginMainActivity();
}
private void beginMainActivity() {
// MainActivity λ₯Ό μ€ννλ intent μμ± λ° νΈμΆ
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}
6. κ²°κ³Ό νλ©΄
'π κ°λ° > μλλ‘μ΄λ' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[μλλ‘μ΄λ] text color κ° white μΈ κ²½μ° (0) | 2021.10.28 |
---|---|
[μλλ‘μ΄λ] λ²νΌ μκΉ λ°κΎΈκΈ° (1) | 2021.10.28 |
[μλλ‘μ΄λ] μμΈμ μ°Ύλ μ€... ^^ (2) | 2021.09.14 |
[μλλ‘μ΄λ] java.net.SocketException: socket failed: EACCES (Permission denied) (0) | 2021.09.14 |
[μλλ‘μ΄λ] AsyncTask μ HttpURLConnection ...(1) Android Sample Code (2) | 2021.08.26 |
λκΈ