How use centerCrop in SplashActivity - android

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.

Related

Splash screen is sometimes distorted and blurred

I have a splash screen activity with the following theme:
<style name="AppTheme.Launcher" parent="Theme.AppCompat.NoActionBar">
<item name="android:background">#drawable/splash_theme</item>
</style>
Here is a part of my manifest:
<activity
android:name=".activities.SplashActivity"
android:theme="#style/AppTheme.Launcher">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
And here is my drawable:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/colorPrimaryDarkBackground" />
<item>
<bitmap
android:gravity="center"
android:src="#drawable/shelpwelt_theme" />
</item>
</layer-list>
At some builds all works perfectly but sometimes the splash screen is completely distorted and blurred but just at the first 2-3 seconds. Then when my splash screen activity reaches onCreate the theme looks perfectly fine.
Here is the problem:
You are using a gif file for this case. And after the given time you said, 2-3 sec it wraps the screen size, so the image gets bigger. That's why it get's blurred on the screen.
Add bottom,left,right,top size to your item.
Change your drawble file to this :
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
android:opacity="opaque">
<item android:drawable="#color/colorPrimaryDarkBackground" />
<item
android:bottom="24dp"
android:left="24dp"
android:right="24dp"
android:top="24dp"
>
<bitmap
android:gravity="center"
android:src="#drawable/shelpwelt_theme" />
</item>
</layer-list>
It might be a scaling issue, try to change splash's layout, instead of designing the entire image and set it as a background, design your layout to have two images one for the gray rectangle and the other for the video icon

Drawable as background of splash theme doesn't keep ratio

In my application, I'm trying to set the splash theme with a drawable background. It works correctly if I use a small image, but when the image is bigger then the screen size, it doesn't work anymore.
The image is correctly scaled horizzontally, but the height isn't, as follows:
I tried every scaletype and gravity, what else can I do?
this is my Theme:
<style name="SplashTheme" parent="AppTheme">
<item name="android:windowBackground">#drawable/background_splash</item>
</style>
This is my background_splash.xml
<item android:drawable="#android:color/white" />
<item
android:left="50dp"
android:right="50dp"
>
<bitmap android:src="#drawable/logo_splash"
android:gravity="center|clip_horizontal"
android:scaleType="centerInside"
/>
</item>
and this is my manifest (relevant code):
<activity
android:name=".activities.SplashScreenActivity"
android:configChanges="orientation|screenSize"
android:theme="#style/SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Any idea?
You can use a layer-list like this in your background_splash.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="#android:color/white"
android:gravity="fill" />
<item
android:drawable="#drawable/logo_splash"
android:gravity="center" />
</layer-list>
This will center your image on the screen and the left space will be filled by the white background color.
Maybe you have to add the image in different sizes like you can read here:
https://developer.android.com/training/multiscreen/screendensities#TaskProvideAltBmp
If you do that you can access the image with the same name. It will look like this your project structure:
If you want to remove the action and status bar in your splash screen, you can add the following line to your SplashTheme:
<item name="android:windowFullscreen">true</item>

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.

Animation in Splash Screen

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?

creating a new transparent activity

im trying to play a video or show a picture on the phone while still being able to control the phone.
the only thing ive managed to do so far is to start a new transparent activity.
that enables me to show whatever i would like. but i cannot control the phone behind the pic/video.
this is my code:
<activity
android:name=".VideoPopActivity"
android:label="#string/app_name"
android:theme="#style/Theme.Transparent" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and in the styles.xml:
<style name="Theme.Transparent" parent="android:Theme">
<item name="android:windowIsTranslucent">true</item>
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:background">#android:color/transparent</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowIsFloating">true</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:windowFrame">#null</item>
open to new suggestion aside from this "trick".....
No, you cannot control an inactive Activity, specifically one that is beneath the active one.
What you'll want to do is create a RelativeLayout that contains your transparent picture as well as the main layout. This will layer them on top of each other. Make sure both are match_parent for both width and height.
<RelativeLayout
... >
<LinearLayout
... >
<!-- This is your main layout -->
</LinearLayout>
<ImageView
android:visibility="gone"
... /> <!-- Your picture, invisible by default -->
</RelativeLayout>
Or, instead of an ImageView, make another layout, in which you can place your video/image content.
This is way to to make activity transparent, however to get more pleasing view, you should make your activity not apaoque, not transparent, as it will give a mirror like or water like view..
you could use,
You should create opaqueStyle.xml in the drawable folder and set your main layout's background as the opaqueStyle.xml..
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp" android:color="#FFFFFFFF" />
<solid android:color="#30646464" />
<corners android:bottomRightRadius="7dp" android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp" android:topRightRadius="7dp"/>
</shape>
Here in <solid android:color="#30646464" /> this line, "#30646464", 30 is for opacity, you can increase or decrease its opacity and else six digits are the color, you can adjust it for urself..

Categories

Resources