Animation in Splash Screen - android

I use this splash screen for my app. It works fine, but I want to use animation. How can I use animation without layouts?
This my java file:
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, NavigationActivity.class);
startActivity(intent);
finish();
}
}
My xml for theme:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/colorMaterialWhite"/>
<item>
<bitmap
android:gravity="center"
android:src="#mipmap/ico" />
</item>
</layer-list>
Style:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
AndroidManifest:
<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>
I want rotate ico while app loading. Thank you.
Is it even possible?

Related

How to change the base color of an application

When I launch my application, the screen goes white before displaying my Splash Screen
I would like to remove if possible or put the background the same color as my Splash Screen
But I do not know how, Can someone help me
Thank you
You need to remove your splash screen code as the white screen is itself a splash, provided by android. You just need to change it according to your need.
You first need to create a drawable with name splash_screen.xml and put this code
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/black"/>
<item
android:drawable="#mipmap/ic_launcher_round"
android:gravity="center"/>
</layer-list>
after that you need to create a activity which launches your MainActivity
Something like this
class OnBoardingActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
DashboardActivity.launch(this)
finish()
}
}
then you need to overwrite the default splash screen with your styles.xml
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_screen</item>
</style>
after that last step is to add this theme in your manifest.
the activity which launches the app will have this style
<activity
android:name=".ui.onboarding.OnBoardingActivity"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
you could use separate activity for your splash screen
xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#dddddd"
tools:context=".SplashScreen">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/ic_icon" />
<TextView
android:id="#+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:text="Splash Screen"
android:textSize="25sp" />
Class
public class SplashScreen extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash_screen);
new Handler().postDelayed(new Runnable(){
#Override
public void run() {
Intent mainIntent = new Intent(getApplicationContext(),MainActivity.class);
SplashScreen.this.startActivity(mainIntent);
SplashScreen.this.finish();
}
}, 2000);
}
}
Manifest
( Launch Activity as SplashActivity )
<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.SplashtoMain">
<activity android:name=".MainActivity"/>
<activity android:name=".SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

Android: Remove white startup screen

I have tried implementing a splash screen in order to remove that white startup screen however, I still find its there. How can I go about changing that white start up screen with a different colour or have my splash screen to go over that white start up screen?
AndroidManifest.xml
<activity
android:name=".SplashActivity"
android:theme="#style/SplashTheme"
android:label="#string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Values/styles.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:statusBarColor">#color/blue</item>
<item name="android:windowDisablePreview">true</item>
<!-- Customize your theme here. -->
</style>
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
<item name="android:statusBarColor">#color/blue</item>
<item name="android:windowDisablePreview">true</item>
</style>
</resources>
values/colors/.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="status_bar_color">#233240</color>
<color name="blue">#233240</color>
<color name="primary_dark">#233240</color>
</resources>
layout/SplashScreen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/blue"
>
</LinearLayout>
MainActivity.java
public class MainActivity extends ReactActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
SplashScreen.show(this, true);
super.onCreate(savedInstanceState);
}
SplashActivity.java
public class SplashActivity extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}

SplashScreen approach defined in xml (without activity) does not appear

I have defined splash screen like many other without external activity, but it doesn't works for me, I don't understand why.
Is there any limitations for images? Also tried for many other images
This is my splash.xml
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item>
<bitmap
android:gravity="center"
android:src="#drawable/splash_logo" />
</item>
</layer-list>
Here preview for splash.xml file in android studio looks like perfectly.
Than I have created style like that
<style name="AppTheme.Launcher">
<item name="android:windowBackground">#drawable/splash</item>
</style>
and assigned it to activity theme inside manifest
<activity
android:theme="#style/AppTheme.Launcher"
android:name=".MainActivity"
android:screenOrientation="portrait">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
this is my activity's
override fun onCreate(savedInstanceState: Bundle?) {
setTheme(R.style.AppTheme)
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
when activity is loaded blank white screen is shown instead of image, maybe for a one second. I searched this approach and seems that it is the same what others were done. Don't understand what's wrong
EDIT:
I have tested it for another device OS 5.0 and it works, but for 6.0 doesn't
EDIT
Remove this from your activity
setTheme(R.style.AppTheme)
Try this
Style.xml
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/splash_background</item>
</style>
splash_background.xml
<?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:gravity="center"
android:src="#mipmap/ic_launcher" />
</item>
</layer-list>
SplashActivity
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
startActivity(new Intent(SplashActivity.this, MainActivity.class));
// close splash activity
finish();
}
}
Manifest
<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>
This should be a comment. But i cannot put a comment. I have faced the same problem. Please check your size of image. Try to compress the image and try again it may help you. Please do let me know.

How use centerCrop in SplashActivity

In my SlashActivity I use only AndroidManifest and style as advised here https://www.bignerdranch.com/blog/splash-screens-the-right-way/.
And in SplashActivity I want use splash.jpg, but this picture changing to screen size.
How I can use centerCrop in my style file or are there other solutions?
My drawble:
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/colorMaterialWhite"/>
<item>
<bitmap
android:gravity="center"
android:src="#drawable/splash" />
</item>
</layer-list>
AndroidManifest:
<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>
SplashActivity:
public class SplashActivity extends AppCompatActivity {
#Override
protected void onCreate(#Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(this, NavigationActivity.class);
startActivity(intent);
finish();
}
}
Style:
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
You might want to add padding to your splash image.
Inside the item tag add android:top, android:bottom, android:right, android:left
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#color/colorMaterialWhite"/>
<item
android:top="200dp"
android:bottom="200dp"
android:left="200dp"
android:right="200dp">
<bitmap
android:gravity="center"
android:src="#drawable/splash" />
</item>
</layer-list>
I have also followed this blog while creating my Splash screen. Generally, the splash screen has a background color and the logo of your app and you can set it as a background. So, you should not require to centerCrop the image in Splash screen. In case that need is there, I would strongly recommend to edit the image using any editor instead of programmatically doing it.

How to remove extra blank space from Menu

I am new in Android and using Overflow Menu in my program,
I need to know few things:
Question 1: How to remove extra blank space in Options, like in : Video, Email
Question 2: Want to hide both Activity Name or Application Name and ICON from FirstActivity
View my code below,
Menu > items.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="#+id/phone"
android:title="#string/phone"
android:icon="#drawable/phone"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/computer"
android:title="#string/computer"
android:icon="#drawable/computer"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/gamepad"
android:title="#string/gamepad"
android:icon="#drawable/gamepad"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/camera"
android:title="#string/camera"
android:icon="#drawable/camera"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/video"
android:title="#string/video"
android:icon="#drawable/video"
android:showAsAction="ifRoom|withText"
/>
<item
android:id="#+id/email"
android:title="#string/email"
android:icon="#drawable/email"
android:showAsAction="ifRoom|withText"
/>
</menu>
Manifest.xml:
<application
android:icon="#drawable/ic_launcher"
android:uiOptions="splitActionBarWhenNarrow"
android:allowBackup="true" >
<activity
android:name="com.sample.menu.HomeActivity"
android:label="Demo App"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.sample.menu.FirstActivity"
android:label="First Activity">
<intent-filter>
<action android:name="com.sample.menu.second" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
FirstActivity.java:
public class FirstActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
getActionBar().setDisplayHomeAsUpEnabled(true);
setContentView(R.layout.activity_first);
getOverflowMenu();
}
For question 2 add
requestWindowFeature(Window.FEATURE_NO_TITLE);
Right before :
setContentView(R.layout.activity_first);
To Full Screen use,
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.my_layout);
FOR OVERFLOW MENU, please elaborate more What u want..?
for your Question 2:
in onCreate()
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
this is to make action bar icon transparent
getActionBar().setIcon(new ColorDrawable(getResources().getColor(android.R.color.transparent)));
in Manifest.xml
<android:theme="#android:style/Theme.NoTitleBar">
For your Question 1:
this link is useful for you

Categories

Resources