SoFunction
Updated on 2025-04-09

Android Theme and the solution to the black screen to start the Android screen

Preface

This article mainly introduces the relevant content about Android Theme and solving the black screen for startup. It is shared for your reference and learning. I won’t say much below. Let’s take a look at the detailed introduction together.

1. Modify Set the global Theme or Activity interface of the app

<application
 android:allowBackup="true"
 android:icon="@drawable/ipod_icon"
 android:label="@string/app_name"
 android:launchMode="singleTask">
<!-- iPodMain interface -->
<activity
 android:name=""
<!-- Use the styles defined above mythou-->
 android:theme="@style/"
 android:label="@string/app_name" >
 <intent-filter>
 <action android:name="" />
 <category android:name="" />
 </intent-filter>
</activity>
//......
</application>

•You can add the above custom styles to the Activity. In addition, it is also possible to add it in Application, and it is a global effect.

•Custom Theme is placed in /res/values/. If you don't have this file, just add one by yourself.

•If there are multiple Activity switches, there may also be a brief black screen problem in the middle. The reason is that when the Activity starts, you need to initialize the loading data. If you want to avoid this, you can add the above style to the Activity you switched.

• Both of the above styles can avoid black screen. You can actually test your program to choose an effect.

•This only avoids the black screen, but if your program initialization is slow, it will still give people the feeling of slow program startup. The program initialization process needs to be optimized by itself.

android:theme="@android:style/" //Activity is displayed as dialog box modeandroid:theme="@android:style/" //Do not display the application title barandroid:theme="@android:style/" //Do not display the application title bar and full screenandroid:theme=" " //The background is whiteandroid:theme="" //There is no title bar on the white backgroundandroid:theme="" //White background, untitle bar, full screenandroid:theme="" //Black backgroundandroid:theme="" //The black background has no title barandroid:theme="" //Black background, untitle bar, full screenandroid:theme="" //Use the system desktop as the application backgroundandroid:theme="" //Use the system desktop as the application background and there is no title barandroid:theme="" //Use the system desktop as the application background, without title bar, full screenandroid:theme="" //Transparent backgroundandroid:theme="" //Transparent background without titleandroid:theme="" //Transparent background without title, full screenandroid:theme=" " //Panel style displayandroid:theme="" //Tablet style display

Theme and Style

In addition to Theme, there are Styles in Android. For example, below is a Style that configures workspace in Launcher.

<style name="WorkspaceIcon">
  <item name="android:layout_width">match_parent</item>
  <item name="android:layout_height">match_parent</item>
  <item name="android:layout_gravity">center</item>
  <item name="android:gravity">center_horizontal</item>
  <item name="android:singleLine">true</item>
  <item name="android:ellipsize">marquee</item>
  <item name="android:textSize">12sp</item>
  <item name="android:textColor">#FFF</item>
  <item name="android:shadowRadius">2.0</item>
  <item name="android:shadowColor">#B0000000</item>
 </style>

Style can be understood as a set of attributes, which is convenient for different View settings. When we use Style in View, it is the same application method as using Theme. So what is the difference between Style and Theme?

The difference between the two is listed below:

• Styles are used on separate Views, such as: Button, TextView, etc.

•The topic is used in the entire application or an activity through the topic, and the topic has a global impact on the entire application or an activity.

•If an application uses a theme and the view under the application also uses styles, then when the theme and the style attributes conflict, the style priority is higher than the theme.

The above is to solve the problem of starting a black screen with the program through Theme, and explain the Theme and Style. Through the Theme configuration, you can actually make a welcome page. However, we all hope that the faster the program starts, the better, so we still need to optimize our programs more.

2. Solve the problem of starting black screen:

Reasons for occurrence:

1 Cause Loading onCreate method It takes time to load data by executing the method. You need to run onCreate and onResume before the interface will be displayed.

2 The main reason for flashing the black screen is that when we start the Activity, we need to run onCreate and onResume before the interface will be displayed. That is to say, some data needs to be processed before it will be displayed. According to this idea, can I avoid black screen by minimizing the initialization work? The truth is that even if you do nothing onCreate, you will still flash black because it takes a certain amount of time to initially resolve the interface. Here is the solution:

solve:

Set background image Theme

&lt;style name="" parent="android:Theme"&gt; 
 &lt;item name="android:windowBackground"&gt;@drawable/ipod_bg&lt;/item&gt; 
 &lt;item name="android:windowNoTitle"&gt;true&lt;/item&gt; 
&lt;/style&gt;

// ps: If you want to set the full screen of this still page, add a sentence:// <item name="android:windowFullscreen">true</item>
//2. Set transparent Theme&lt;style name="" parent="android:Theme"&gt; 
 &lt;item name="android:windowIsTranslucent"&gt;true&lt;/item&gt; 
 &lt;item name="android:windowNoTitle"&gt;true&lt;/item&gt; 
&lt;/style&gt;

I have defined two types of themes above. The first type of theme is to set a background image. When the program starts, first display this background image to avoid a black screen. The second Theme is to set the style to transparent. After the program starts, the screen will not be black, but will be transparent. It will not be displayed at one time until the interface is initialized.

Here are the advantages and disadvantages of the two methods:

•Theme1 program starts quickly, the interface first displays the background image, and then refreshes other interface controls. Refreshing the feeling of out-of-sync.

•Theme2 gives people the feeling of slow start of the program, and the interface is flashed at one time and refreshed and synchronized.

Summarize

The above is the entire content of this article. I hope that the content of this article has a certain reference value for everyone's study or work. If you have any questions, you can leave a message to communicate. Thank you for your support.