Skip to content

Instantly share code, notes, and snippets.

@senamit2708
Last active June 9, 2019 10:51
Show Gist options
  • Save senamit2708/75cec1abdcc0d65bc87a7ed0f8544d6e to your computer and use it in GitHub Desktop.
Save senamit2708/75cec1abdcc0d65bc87a7ed0f8544d6e to your computer and use it in GitHub Desktop.
Cool loading of android app
//create this file inside the drawable section...
//here jpg imge is used
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/colorPrimary" />
<item>
<bitmap android:src="@drawable/tuktukone"
android:gravity="center" />
</item>
</layer-list>
App takes cool time to start the app...
I am using android jetpack mvvm archietecture to create app..so i have only one activity and rest are fragments.
So, create one more activity, because we need to use one style here..so dont distrub your main activity for this.
one new activity is created,
then one drawable ...and in this drawable use image from drawable(Here is a catch dont use vector image or any other type of file ..use jpg image here)
now create one style and then in that style inside window background item put that newly created drawable
--inside toolbar style theme, add one more line
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
put this style in the mainfest of that activity
and then run it
sources:-
https://medium.com/@ssaurel/create-a-splash-screen-on-android-the-right-way-93d6fb444857
https://developer.android.com/topic/performance/vitals/launch-time#themed
https://stackoverflow.com/questions/54053614/splash-screen-error-android-content-res-resourcesnotfoundexception-drawable
<activity android:name=".activities.SplashActivity"
android:theme="@style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white"
tools:context="amit.diary.studentdiaryentryTwo.activities.SplashActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
Intent intent = new Intent(SplashActivity.this, SchoolDiaryMainActivity.class);
startActivity(intent);
finish();
}
}
<style name="ToolbarTheme" parent="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<!-- android:textColorPrimary is the color of the title text in the Toolbar -->
<item name="android:textColorPrimary">@android:color/black</item>
<!-- actionMenuTextColor is the color of the text of action (menu) items -->
<item name="actionMenuTextColor">@android:color/holo_green_light</item>
<!-- Tints the input fields like checkboxes and text fields -->
<item name="colorAccent">@color/colorPrimary</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
</style>
<style name="SplashTheme" parent="Theme.MaterialComponents.Light.NoActionBar">
<item name="android:windowBackground">@drawable/background</item>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment