Android

[Android]Splash Screen 구현 Java

Wootaeng 2021. 9. 20. 00:06
728x90

 

Splash 효과란?

- 앱을 실행할 때 바로 앱으로 들어가는 것이 아니라 일정시간 지정한 화면을 보여주고 

인앱으로 넘어가는 것을 말한다.

 

res - drawable 폴더에

<vector android:height="24dp" android:tint="#201F1F"
    android:viewportHeight="24" android:viewportWidth="24"
    android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="@android:color/white" android:pathData="M19,7h-8v6h8L19,7zM21,3L3,3c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,1.98 2,1.98h18c1.1,0 2,-0.88 2,-1.98L23,5c0,-1.1 -0.9,-2 -2,-2zM21,19.01L3,19.01L3,4.98h18v14.03z"/>
</vector>

<Splash screen 에 적용할 이미지>


 

 

res - drawable 폴더에

 

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <gradient

        android:angle="90"
        android:startColor="#8AD0CC"
        android:endColor="#1c8bd8"
        android:type="linear"/>
    <corners
        android:radius="0dp"/>
</shape>

 

지난 시간 만든 그라데이션 xml을 추가하여 배경으로 지정한다

 

 

[Android]그라데이션 적용 -JAVA

안드로이드 앱을 만들다보면 Splash 화면을 구성하거나 다른 UI 를 구성할때 그라데이션을 적용하는 일이 종종 있다. 그라데이션을 만드는 법을 정리해보자 res - > drawable 폴더에 그라데이션.xml 파

wootange31.tistory.com

 

 

 

위의 두 xml 을 SplashScreen  으로 표현한 layout 에 적용한다

 

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
    android:orientation="vertical"
    tools:context=".MainActivity"
    android:background="@drawable/splash_bg_gradient">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="120dp"
        android:layout_height="120dp"
        android:layout_centerInParent="true"
        app:srcCompat="@drawable/ic_baseline_picture_in_picture_24" />
    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="ImageView"
        android:layout_below="@id/imageView"
        android:layout_centerHorizontal="true"
        android:textStyle="bold"
        android:textColor="@color/black"
        android:textSize="24sp"
        />

</RelativeLayout>

 

<나는 최초에 실행되길 원해서 activity_main.xml 에 적용>


 

 

그 후 액티비티에서 코드를 적용 시켜주면 된다

 

public class MainActivity extends AppCompatActivity{


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        //화면 계속 켜짐
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

        //delay 실행
        new Handler().postDelayed(new Runnable() {//3초 후 실행행           
            @Override
            public void run() {
                Intent intent = new Intent(MainActivity.this, LocalfolderList.class);
                startActivity(intent);
                finish();

            }
        }, 3000);

    }
   
}

 

코드를 위처럼 작성하게 되면

 

앱 실행시

해당 이미지가 먼저 구현되고 

앱으로 넘어가는 것을 확인 할 수 있다. 

 

 

728x90
반응형