【问题标题】:Splashscreen not getting displayed闪屏不显示
【发布时间】:2016-06-18 04:55:52
【问题描述】:

我有一个 Android 应用程序,我想在其中显示 6 秒的启动画面,但启动应用程序没有显示启动画面,而是显示了之前我的起始页的屏幕。

这是splashscreen.java 文件:

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Handler;
public class splashscreen extends AppCompatActivity {
    private static int SPLASH_TIME_OUT = 6000;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splashscreen);

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

            // Using handler with postDelayed called runnable run method

            @Override
            public void run() {
                Intent i = new Intent(splashscreen.this, LoginActivity.class);
                startActivity(i);

                // close this activity
                //finish();
            }
        }, 6*1000);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_splashscreen, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

这是我的manifest 文件-

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.admin.doccorduser" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <!-- Splash screen -->
        <activity
            android:name=".splashscreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".LoginActivity"
            android:label="@string/app_name" >
        </activity>
        <activity
            android:name=".RegActivity"
            android:label="@string/title_activity_reg" >
        </activity>
        <activity
            android:name=".Services"
            android:label="@string/title_activity_services" >
        </activity>
        <activity
            android:name=".viewExistingApp"
            android:label="@string/title_activity_view_existing_app" >
        </activity>
        <activity
            android:name=".DocumentAdvisor"
            android:label="@string/title_activity_document_advisor" >
        </activity>
        <activity
            android:name=".ChangePassword"
            android:label="@string/title_activity_change_password" >
        </activity>
        <activity
            android:name=".TrackStatus"
            android:label="@string/title_activity_track_status" >
        </activity>
        <activity
            android:name=".ChildRegister"
            android:label="@string/title_activity_child_register" >
        </activity>
        <activity
            android:name=".FathersDetails"
            android:label="@string/title_activity_fathers_details" >
        </activity>
        <activity
            android:name=".MothersDetails"
            android:label="@string/title_activity_mothers_details" >
        </activity>
        <activity
            android:name=".AppNumber"
            android:label="@string/title_activity_app_number" >
        </activity>
        <activity
            android:name=".SignUp"
            android:label="@string/title_activity_sign_up" >
        </activity>
    </application>

</manifest>

这是splashscreen.xml文件-

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="16dp"
    android:paddingTop="56dp"
    android:paddingBottom="56dp"
    android:background="@drawable/back1"
    tools:context="com.example.lenovo.doccorduser.splashscreen">

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/foetus"
        android:layout_alignTop="@+id/textView4"
        android:layout_centerHorizontal="true" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        android:src="@mipmap/doccord"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="DocCord"
        android:textStyle="bold"
        android:id="@+id/textView4"
        android:layout_below="@+id/imageView"
        android:layout_centerHorizontal="true"
        android:focusable="false"
        android:textColor="@android:color/holo_orange_light" />

</RelativeLayout>

请帮忙...

【问题讨论】:

  • 代码似乎没问题。尝试清理和重建您的项目。
  • Errors 中有任何 Logcat 吗?然后发布它。
  • 您的代码没有任何问题。只需确保您正在修改正确的清单文件即可。

标签: android splash-screen


【解决方案1】:

首先清理您的项目,

Build -> Clean Project

然后再次运行。它会起作用的。

【讨论】:

    【解决方案2】:

    嗨,试试这个代码:

    SplashScreen.java

    public class splashscreen extends AppCompatActivity {
    
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splashscreen);
        Thread timerThread = new Thread(){
            public void run(){
                try{
                    sleep(6000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent intent = new Intent(splashscreen.this,MainActivity.class);
                    startActivity(intent);
                }
            }
        };
        timerThread.start();
    }
    
    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }
    

    }

    SplashScreen.xml

    ,

    <ImageView
        android:src="@drawable/mobilewallpapers"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
    

    AndroidManifest

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
            </intent-filter>
        </activity>
        <activity android:name=".splashscreen">
            <intent-filter>
                <action android:name="android.intent.action.MAIN">
    
                </action>
                <category android:name="android.intent.category.LAUNCHER">
    
                </category>
            </intent-filter>
        </activity>
    </application>
    

    希望它有效;)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-01-31
      • 2014-12-24
      • 2017-07-22
      • 2021-01-02
      • 1970-01-01
      • 2012-09-09
      相关资源
      最近更新 更多