Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 屏幕是黑色的_Java_Android_Xml_Splash Screen - Fatal编程技术网

Java 屏幕是黑色的

Java 屏幕是黑色的,java,android,xml,splash-screen,Java,Android,Xml,Splash Screen,因此,我已经看过很多教程,它们展示了使用以下代码实现android SplashScreen的“正确方法”: ^SplashActivity.java <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.rws.jsonclassifier"> <application android:allowBackup="true" android:ico

因此,我已经看过很多教程,它们展示了使用以下代码实现android SplashScreen的“正确方法”:

^SplashActivity.java

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.rws.jsonclassifier">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:roundIcon="@mipmap/ic_launcher_round"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <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>

    <activity android:name=".MainActivity"></activity>
</application>

^AndroidManifest.xml

<resources>

<!-- 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>
  package com.rws.jsonclassifier;

import android.content.Intent;

import android.os.Bundle;

import android.os.Handler;

import android.support.v7.app.AppCompatActivity;

public class SplashActivity extends AppCompatActivity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

}
<style name="AppTheme.Launch" parent="AppTheme.NoActionBar">
        <item name="android:windowBackground">@drawable/activity_launch</item>
</style>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/product_logo_windesheim" />
    </item>
</layer-list>
我正在使用代码并遵循教程中显示的设置步骤,但由于某种原因,我得到了一个全黑屏幕,而不是应用程序图标的蓝色背景。
有什么想法吗?

我认为这是因为您没有使用
处理程序来导航到下一个
活动。我也在我的一个应用程序中实现了这一点

AndroidManifest.xml

<activity
     android:name=".view.LaunchActivity"
     android:label="@string/app_name"
     android:launchMode="singleTask"
     android:theme="@style/AppTheme.Launch">
     <intent-filter>
          <action android:name="android.intent.action.MAIN" />

          <category android:name="android.intent.category.LAUNCHER" />
          <category android:name="android.intent.category.INFO" />
      </intent-filter>
 </activity>
请参阅此处的完整来源:


在onCreate中使用处理程序,并尝试为splash活动添加新的splash.xml布局视图:

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

        Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();
       }
       }, 2000);
    }
您可以在splash.xml布局中添加自己的设计

如果您仍然想使用自己的编码方式,那么我认为错误出在drawable/splash_background.xml

<resources>

<!-- 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>
  package com.rws.jsonclassifier;

import android.content.Intent;

import android.os.Bundle;

import android.os.Handler;

import android.support.v7.app.AppCompatActivity;

public class SplashActivity extends AppCompatActivity {

    @Override

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }

}
<style name="AppTheme.Launch" parent="AppTheme.NoActionBar">
        <item name="android:windowBackground">@drawable/activity_launch</item>
</style>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:drawable="@android:color/white" />
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/product_logo_windesheim" />
    </item>
</layer-list>
将ic_launcher添加到您的drawable文件夹,然后更改

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


之后

super.onCreate(savedInstanceState);


另外,正如@Nabil所说的那样添加处理程序

它不是
SplashScreen
为空,它的
main活动
是因为您在onCreate中启动了它。使用延迟处理程序,您将看到飞溅。同时也提到了很多你已经看过的教程。我认为任何splash教程都不会直接在
oncreate()
中启动活动。这是我在你的时间里使用的xDThanx代码!使用这段代码,我仍然可以看到黑屏。一个较长的,但仍然是黑色的S:也添加一个新的splash.xml布局,并根据您的意愿进行设计。我已经编辑了答案,如果您仍然没有解决方案,请立即尝试使用Thanx,以供参考!我将检查它以将其与我的代码进行比较,bot实现处理程序只会使黑屏变长…:(您是否尝试将
AppCompatActivity
替换为
Activity
?是的,但它仍然是黑色的哈哈哈,我看到您接受了我的答案。您最终做了什么使其工作?我几乎将您的代码实现到了我的项目中,并使用github链接作为参考,查看ScheduleActivity.class是如何实现的布局文件夹上没有任何活动飞溅…我以为这就是开始这种实现的想法(?)