1. BaseApplication 클래스에 AppCompatDialog를 생성
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 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | public class BaseApplication extends Application { private static BaseApplication baseApplication; AppCompatDialog progressDialog; public static BaseApplication getInstance() { return baseApplication; } @Override public void onCreate() { super.onCreate(); baseApplication = this; } public void progressON(Activity activity, String message) { if (activity == null) { return; } if (progressDialog != null && progressDialog.isShowing()) { progressSET(message); } else { progressDialog = new AppCompatDialog(activity); progressDialog.setCancelable(false); progressDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); progressDialog.setContentView(R.layout.progress_loading); progressDialog.show(); } final LottieAnimationView lottieAnimationView = (LottieAnimationView) progressDialog.findViewById(R.id.iv_frame_loading); lottieAnimationView.playAnimation(); TextView tv_progress_message = (TextView) progressDialog.findViewById(R.id.tv_progress_message); if (!TextUtils.isEmpty(message)) { tv_progress_message.setText(message); } } public void progressSET(String message) { if (progressDialog == null || !progressDialog.isShowing()) { return; } TextView tv_progress_message = (TextView) progressDialog.findViewById(R.id.tv_progress_message); if (!TextUtils.isEmpty(message)) { tv_progress_message.setText(message); } } public void progressOFF() { if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } } } | cs |
2. https://www.lottiefiles.com/ 에서 json 파일을 다운로드
assets Folder 생성한후 json 파일 붙여넣기
3 . res -> layout -> progress_loading.xml
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 28 29 30 31 32 | <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:id="@+id/loading_frame_container" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_centerInParent="true" android:gravity="center" android:orientation="vertical"> <com.airbnb.lottie.LottieAnimationView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/iv_frame_loading" app:lottie_loop="true" app:lottie_fileName="loading.json" app:lottie_autoPlay="true" /> <TextView android:id="@+id/tv_progress_message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="16dp" android:text="Loading.." android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#ffffff" /> </LinearLayout> </RelativeLayout> | cs |
fileName 설정 = json 파일 이름
3. app gradle dependencies 에 추가 -> sync
compile 'com.airbnb.android:lottie:2.1.0'
4. Manifest 에 name 속성 추가
<application
android:name=".BaseApplication"
android:allowBackup="true"
android:icon="@mipmap/icon"
android:label="@string/app_name"
android:roundIcon="@mipmap/icon"
android:supportsRtl="true"
android:theme="@style/AppTheme">
5. 로딩이 필요한 부분에 추가
BaseApplication.getInstance().progressON(MainActivity.this, null);
로딩 시작
BaseApplication.getInstance().progressOFF();
로딩 종료
'Android' 카테고리의 다른 글
CustomTitlebar 재활용 (0) | 2017.11.20 |
---|---|
슬라이더 무한 + 자동 스크롤 + Indicator 연동 (ViewPager) (0) | 2017.11.20 |
리사이클러뷰 리스트 비었을때 EmptyView 보여주기 (0) | 2017.11.11 |
Easy Way] TedPermission + 현재 위치 -> 구글맵 (0) | 2017.11.11 |
횡스크롤 안되는 FragmentViewPager + 하단 네비게이션 (1) | 2017.11.09 |