Source: https://www.edwith.org/boostcourse-android/lecture/20495/
1. 실행 결과 화면
2. AndroidManifest.xml
XML 레이아웃을 만들어 인플레이션하는 방식이 아니라 Manifest.xml에서 theme 속성으로 스타일을 지정하는 방식이다.
일반적으로 setContentView 를 이용하여 레이아웃을 만드는 것보다 테마를 이용해서 화면을 보여주는 것이 더 빠르다.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.tistory.qlyh8.practice"> <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"> <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"/> </application> </manifest> | cs |
3. values/styles.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | <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/splash_bg</item> </style> </resources> | cs |
4. res/drawable/splash_bg.xml
1 2 3 4 5 6 7 | <?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/splash_bg_gradient"/> <item android:top="210dp"> <bitmap android:src="@drawable/image22" android:gravity="top"/> </item> </layer-list> | cs |
5. res/drawable/splash_bg_gradient.xml
1 2 3 4 5 6 7 8 9 10 11 | <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"> <gradient android:startColor="#FF3E50B4" android:centerColor="#FF7288DB" android:endColor="#FF7288DB" android:angle="90" android:centerY="0.5"/> <corners android:radius="0dp" /> </shape> | cs |
6. SplashActivity.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | package com.tistory.qlyh8.practice; import android.content.Intent; import android.os.Bundle; import android.os.Handler; import android.support.annotation.Nullable; import android.support.v7.app.AppCompatActivity; public class SplashActivity extends AppCompatActivity { Handler handler = new Handler(); @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); // 2초 뒤에 main 화면이 보임 handler.postDelayed(new Runnable() { @Override public void run() { startActivity(new Intent(getApplicationContext(), MainActivity.class)); finish(); } }, 2000); } } | cs |
7. 참고
- Splash Sample: https://github.com/dudmy/blog-sample
- Material Design: https://material.io/design/
'Android' 카테고리의 다른 글
슬라이딩 애니메이션 (Sliding Animation) (0) | 2018.08.24 |
---|---|
트윈 애니메이션 (Tween Animation) (0) | 2018.08.24 |
스레드 애니메이션 (Thread Animation) (0) | 2018.08.24 |
RecyclerView (리사이클러뷰) (0) | 2018.08.23 |
음성 녹음하기 (0) | 2018.08.23 |