У меня есть осуществленный splashcreen посредством одной activity
что надувается спесью Ваш layout
с центрованным изображением, но что я нахожусь, что, если это первый раз, который устанавливает app, в течение груза / компиляции он является экраном в мишени, более или менее 6 секунд, второй раз, что ты инициализируешь app, инициализируется прямо с SplashScreen.
Образно так
Первый раз, который выполняет app после установки, или удалять данные о меню конфигурации
(click открываться app)......................... (splashscreen)------(занесло в список)
Второй раз, который себе открывает app
(click открываться app) (splashscreen)------(занесло в список)
Мой вопрос, если есть какой-то способ помещать splashcreen в течение этого периода пред-груза Android.
Manifest.xml
<activity
android:name=".SplashActivity"
android:configChanges="keyboardHidden|orientation|screenSize"
android:theme="@style/AppTheme.SplashTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Стиль AppTheme.SplashTheme
Темы, которую получает в наследство activity
<style name="AppTheme.SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
</style>
Layout XML splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorSplashScreen">
<LinearLayout
android:id="@+id/splashscreen"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:contentDescription="@string/about.alt_logo"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_gravity="center"/>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/app_name"
android:layout_marginTop="8dp" />
</LinearLayout>
</LinearLayout>
SplashActivity.java
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.widget.LinearLayout;
/*
config_longAnimTime = 400
config_mediumAnimTime = 300
config_shortAnimTime = 150
*/
public class SplashActivity extends AppCompatActivity {
private String TAG = "SplashActivity";
@Override
protected void onCreate(Bundle savedInstanceState) {
final int SPLASH_DISPLAY_LENGTH = 1200;
final int SPLASH_DISPLAY_OFFSET = getResources().getInteger(android.R.integer.config_shortAnimTime);;
super.onCreate(savedInstanceState);
setContentView(R.layout.splash_screen);
Log.d(TAG, "onCreate() called with: " + "savedInstanceState = [" + savedInstanceState + "]");
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
final LinearLayout img = (LinearLayout) SplashActivity.this.findViewById(R.id.splashscreen);
Animation fadeOut = new AlphaAnimation(1, 0);
fadeOut.setInterpolator(new AccelerateInterpolator());
fadeOut.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime));
fadeOut.setAnimationListener(new Animation.AnimationListener()
{
public void onAnimationEnd(Animation animation)
{
img.setVisibility(View.GONE);
handler.postDelayed(new Runnable() {
@Override
public void run() {
//Create an intent that will start the main activity.
Intent mainIntent = new Intent(SplashActivity.this, MainActivity.class);
SplashActivity.this.startActivity(mainIntent);
//Apply splash exit (fade out) and main entry (fade in) animation transitions.
overridePendingTransition(R.anim.zoom_enter, android.R.anim.fade_out);
//Finish splash activity so user cant go back to it.
SplashActivity.this.finish();
}
}, SPLASH_DISPLAY_OFFSET);
}
public void onAnimationRepeat(Animation animation) {}
public void onAnimationStart(Animation animation) {}
});
img.startAnimation(fadeOut);
Log.d(TAG, "finish SplashScreen: " + SPLASH_DISPLAY_LENGTH);
}
}, SPLASH_DISPLAY_LENGTH);
}
}
Обновление: Он является белым экраном, потому что он получает в наследство темы light, потому что, если я добавляю стиль темы, - черный экран.
<item name="android:background">#FF000000</item>
<item name="android:colorBackground">#FF000000</item>
Я думаю, что решение заболевает в помогании, рисовать значок посредством груза темы перед тем, как использовать layout xml, открываться app---,> к себе применяет тему----> груз layout в интерфейсе.
Update Leyendo этот post Работоспособный splashscreen (в) AГ±ado сделал
непрозрачными Определять фон splashscreen в drawable background_splash.xml
<?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/colorSplashScreen"/>
<item android:top="-48dp">
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
Применило верхнее перемещение, чтобы налаживать хорошо ее transiciГіn экрана пред-груз к splashscreen
Распределять как фон drawable, созданный в styles.xml
<style name="AppTheme.SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowEnterAnimation">@android:anim/fade_in</item>
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
Из шага удалило мысль иметь текст, который появляется под значком app, потому что не найденный, как делание этого прямо как drawable.
layout splash_screen.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:background="@color/colorSplashScreen">
<LinearLayout
android:id="@+id/splashscreen"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical|center_horizontal">
<ImageView
android:layout_width="wrap_content"
android:contentDescription="@string/about.alt_logo"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_gravity="center"/>
</LinearLayout>
CГіdigo опциональный , чтобы менять тему в полет, в случае когда не делает splascreen с промежуточным activity:
public class MyMainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
setTheme(R.style.Theme_MyApp); //Tu Tema general
super.onCreate(savedInstanceState);
// ...
}
}
Когда ты хочешь, чтобы после того, как инициализируешь экран начала приложения (SplashScreen), он не показал этот причиняющий беспокойство белый фон, я смог быть решен легко создавая тему, которую ты связал бы с активностью:
<style name="SplashTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowBackground">@drawable/fondo_splash</item>
</style>
В действительности свойство, которое определяет фон после того, как инициализирует активность, android:windowBackground
и ты можешь добавлять изображение (@drawable/
)
<item name="android:windowBackground">@drawable/fondo_splash</item>
или цвет (@color/
):
<item name="android:windowBackground">@color/fondo_splash</item>
Внутри нашего AndroidManifest.xml
мы можем определять тему в уровне приложения:
<application
android:theme="@style/SplashTheme">
или какой-то специфической активности:
<activity android:name=".SplashScreenActivity"
android:theme="@style/SplashTheme" >
этим всегда мы заверяем в том, что загружаем фон (drawable или цвет), перед тем, как загружать изображение или инициализировать полностью приложение.