앱 시작시 흰색 화면을 수정하는 방법은 무엇입니까?
시작할 때 2 초 동안 흰색 화면을 표시하는 Android 앱이 있습니다. 내 다른 앱은이 작업을 수행하지 않지만이 작업은 수행합니다. 나는 또한 이것을 고칠 것이라는 희망으로 스플래시 스크린을 구현했습니다. 스플래시 화면 수면 시간을 늘려야합니까? 감사.
AndroidManifest.xml 파일의 시작 활동에 투명 테마를 언급하기 만하면됩니다.
처럼:
<activity
android:name="first Activity Name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Activity
대신 클래스로 화면을 확장하십시오 AppCompatActivity
.
처럼 :
public class SplashScreenActivity extends Activity{
----YOUR CODE GOES HERE----
}
이것을 사용자 정의 스타일에 넣으면 모든 문제가 해결됩니다. 해키 반투명 수정을 사용하면 작업 표시 줄과 탐색 표시 줄이 반투명 해지고 스플래시 화면 또는 기본 화면이 스파게티처럼 보입니다.
<item name="android:windowDisablePreview">true</item>
튜브처럼 .. 처음에는 흰색 화면 대신 아이콘 화면을 표시합니다. 그리고 2 초 후에 홈 화면이 표시됩니다.
먼저 res / drawable에서 XML 드로어 블을 만듭니다.
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:drawable="@color/gray"/>
<item>
<bitmap
android:gravity="center"
android:src="@mipmap/ic_launcher"/>
</item>
</layer-list>
다음으로 이것을 테마에서 스플래시 활동의 배경으로 설정합니다. styles.xml 파일로 이동하여 스플래시 활동에 대한 새 테마를 추가하십시오.
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
</style>
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/background_splash</item>
</style>
</resources>
새 SplashTheme에서 창 배경 속성을 XML 드로어 블로 설정합니다. AndroidManifest.xml에서 스플래시 활동의 테마로이를 구성하십시오.
<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>
이 링크는 원하는 것을 제공합니다. 단계별 절차. https://www.bignerdranch.com/blog/splash-screens-the-right-way/
최신 정보:
는 다음 layer-list
과 같이 더 간단 할 수 있습니다 ( <bitmap>
태그 와 달리 중앙 로고에 벡터 드로어 블도 허용 ).
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Background color -->
<item android:drawable="@color/gray"/>
<!-- Logo at the center of the screen -->
<item
android:drawable="@mipmap/ic_launcher"
android:gravity="center"/>
</layer-list>
다음과 같이 style.xml에서 스타일을 만드십시오.
<style name="Theme.Transparent" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
AndroidManifest의 활동과 함께 다음과 같이 사용하십시오.
<activity android:name=".ActivitySplash" android:theme="@style/Theme.Transparent">
Cyril Mottier의이 멋진 게시물을 읽어야합니다. Android 앱 출시가 멋지게 만들어졌습니다.
You need to customise your Theme
in style.xml and avoid to customise in your onCreate
as ActionBar.setIcon/setTitle/etc.
See also the Documentation on Performance Tips by Google.
Use Trace View
and Hierarchy Viewer
to see the time to display your Views: Android Performance Optimization / Performance Tuning On Android
Use AsyncTask
to display some views.
This is my AppTheme on an example app:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:windowIsTranslucent">true</item>
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
As you can see, I have the default colors and then I added the android:windowIsTranslucent
and set it to true
.
As far as I know as an Android Developer, this is the only thing you need to set in order to hide the white screen on the start of the application.
Both properties works use any one of them.
<style name="AppBaseThemeDark" parent="@style/Theme.AppCompat">
<!--your other properties -->
<!--<item name="android:windowDisablePreview">true</item>-->
<item name="android:windowBackground">@null</item>
<!--your other properties -->
</style>
The user543 answer is perfect
<activity
android:name="first Activity Name"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
But:
You'r LAUNCHER Activity must extands Activity, not AppCompatActivity as it came by default!
The white background is coming from the Apptheme.You can show something useful like your application logo instead of white screen.it can be done using custom theme.in your app Theme just add
android:windowBackground=""
attribute. The attribute value may be a image or layered list or any color.
i also had the same problem in one of my project. I resolved it by adding some following parameters in the theme provided to the splash screen.
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
You can find the reason and resolution in this blog post written by me. Hope it helps.
It can be fixed by setting the theme in your manifest as
<activity
android:name=".MySplashActivityName"
android:theme="@android:style/Theme.Translucent.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
and after that if you are getting
java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
then you may need to extend Activity instead of AppCompatActivity in your MySplashActivity.
Hope it helps!
Below is the link that suggests how to design Splash screen. To avoid white/black background we need to define a theme with splash background and set that theme to splash in manifest file.
https://android.jlelse.eu/right-way-to-create-splash-screen-on-android-e7f1709ba154
splash_background.xml inside res/drawable folder
<?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>
Add below styles
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
<!-- Splash Screen theme. -->
<style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
<item name="android:windowBackground">@drawable/splash_background</item>
</style>
In Manifest set theme as shown below
<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>
White background is caused because of the Android starts while the app loads on memory, and it can be avoided if you just add this 2 line of code under SplashTheme.
<item name="android:windowDisablePreview">true</item>
<item name="android:windowIsTranslucent">true</item>
you should disable Instant Run android studio Settings.
File>Settings>Build,Execution, Deployment>Instant Run unCheck all options shown there.
Note: White screen Issue due to Instant Run is only for Debug builds,this Issue will not appear on release builds.
Try the following code:
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowActionBar">false</item>
<item name="android:windowFullscreen">true</item>
<item name="android:windowContentOverlay">@null</item>
<item name="android:windowIsTranslucent">true</item>
</style>
This code works for me and will work on all Android devices.
Its Solution is very Simple!
There are Three Basic Reasons for This problem
- You are doing Heavy / Long running / Complex task in onCreateVeiw Function.
- If your are using Thread. Then Thread Sleep time may be very large.
- 타사 라이브러리를 사용하는 경우 . 앱 시작시 초기화 되는 것은 이 문제를 일으킬 수 있습니다.
해결책 :
해결책 1 :
Remove the Heavy Task from onCreateView() function and place it some where appropriate place.
해결책 2 :
Reduce the Thread Sleep time.
해결책 3 :
Remove the Third party library at app initialize at implement them with some good strategy.
제 경우에는이 문제를 일으키는 Sugar ORM을 사용하고 있습니다.
개선하려면 공유하세요.
참고 URL : https://stackoverflow.com/questions/20546703/how-to-fix-white-screen-on-app-start-up
'IT박스' 카테고리의 다른 글
“경고! (0) | 2020.08.14 |
---|---|
편집기에서 재생할 때 Xcode Simulator 애니메이션이 매우 느림 (0) | 2020.08.14 |
단위 테스트가 그렇게 훌륭하다면 왜 더 많은 회사에서 수행하지 않습니까? (0) | 2020.08.14 |
쉘 변수에서 웹 페이지의 내용을 얻는 방법은 무엇입니까? (0) | 2020.08.13 |
Nant 0.91에서 구성 오류를 해결하려면 어떻게해야합니까? (0) | 2020.08.13 |