Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android splash screen does not display image full screen

Tags:

android

I have the code as below in my Android app.

My res/values/styles.xml:

   <style name="FullScreen" parent="@style/Theme.AppCompat.Light">
   <item name="windowNoTitle">true</item>
   <item name="windowActionBar">false</item>
   <item name="android:windowFullscreen">true</item>
   <item name="android:windowContentOverlay">@null</item>
   <item       name="android:windowBackground">@drawable/background_splash</item>
   </style>

res/drawable/background_splash.xml:

  <item

     android:drawable="@color/colorPrimaryDark"/>

   <item>
      <bitmap
        android:gravity="center"
        android:src="@mipmap/image1"/>
   </item>

AndroidManifest.xml:

    <activity
      android:name=".SplashActivity"
      android:theme="@style/FullScreen">
    <intent-filter>
      <action android:name="android.intent.action.MAIN"/>

      <category android:name="android.intent.category.LAUNCHER"/>
    </intent-filter>

SplashActivity.java:

    public class SplashActivity extends AppCompatActivity {

    private static int SPLASH_TIME_OUT = 5000;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_splash);

    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            Intent i = new Intent(SplashActivity.this,  MainActivity.class);
            startActivity(i);
            finish();
        }
        }, SPLASH_TIME_OUT);
       }
    }

I have the image1 with appropriate resolution/size present in the res folder. But the splash screen does not display the image covering full screen but displays with reduced size only some part of the screen. Can you please advice what needs to be done. I went through some of the suggestions present on some sites but it did not help.

like image 373
dacscan3669 Avatar asked Aug 26 '16 10:08

dacscan3669


People also ask

How do I make my android activity full screen?

Using Android Studio (current version is 2.2. 2 at moment) is very easy to add a fullscreen activity. See the steps: Right click on your java main package > Select “New” > Select “Activity” > Then, click on “Fullscreen Activity”.

What is the size of splash screen Android?

Splash Screen dimensions App icon with an icon background: This should be 240×240 dp, and fit within a circle of 160 dp in diameter. App icon without an icon background: This should be 288×288 dp, and fit within a circle of 192 dp in diameter.

What is splash screen image?

A splash screen is a graphical control element consisting of a window containing an image, a logo, and the current version of the software. A splash screen can appear while a game or program is launching. A splash page is an introduction page on a website.


4 Answers

In your res/drawable/background_splash.xml, change android:gravity you can use fill, in my case I used top|fill_horizontal for horizontal fill only, choose the combination you want.

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">

   <item android:drawable="@color/White"/>

   <item>
       <bitmap
           android:gravity="top|fill_horizontal"
           android:src="@drawable/splash"/>
   </item>
</layer-list>
like image 67
José Lozano Hernández Avatar answered Nov 15 '22 13:11

José Lozano Hernández


code for activity_splash.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorAccent"
    tools:context=".SplashActivity">

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:srcCompat="@drawable/icon"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        />
</android.support.constraint.ConstraintLayout>

Code for Splash.java

import android.content.Intent;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

public class SplashActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getSupportActionBar().hide();
        setContentView(R.layout.activity_splash);
        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent i = new Intent(SplashActivity.this,MainActivity.class);
                startActivity(i);
                finish();
            }
        },2000);
    }
}
like image 40
Bhagirath Galathiya Avatar answered Nov 15 '22 13:11

Bhagirath Galathiya


I have Done this program. Is this what you are looking for? this is your main XML

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res  
/android"
android:layout_width="match_parent"
android:background="@drawable/android"
android:layout_height="match_parent">

And mainActivity

 public class MainActivity extends AppCompatActivity {
// Splash screen timer
private static int SPLASH_TIME_OUT = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    new Handler().postDelayed(new Runnable() {

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(MainActivity.this, YourNextActivity.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
}}

And Manifest

 <activity android:name=".MainActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN"
                android:theme ="@android:style/Theme.Black.NoTitleBar.Fullscreen"/>

            <category android:name="android.intent.category.LAUNCHER" />
like image 21
Niroj Avatar answered Nov 15 '22 12:11

Niroj


use parent of theme

parent="@style/Theme.AppCompat.Light.NoTitleBar.Fullscreen"

like image 31
Shuddhatm Jain Avatar answered Nov 15 '22 14:11

Shuddhatm Jain