Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/385.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/226.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 在android应用程序中显示闪屏_Java_Android_User Interface_Apk_Splash Screen - Fatal编程技术网

Java 在android应用程序中显示闪屏

Java 在android应用程序中显示闪屏,java,android,user-interface,apk,splash-screen,Java,Android,User Interface,Apk,Splash Screen,您是否曾在许多应用程序中看到过在启动第一个活动之前出现的页面,不知怎的,它就像一个等待页面?!我是android的初学者,当我点击我的应用程序,首先出现一个空白的白色页面,然后在3秒后主要活动出来。但在许多应用程序中,在第一次活动之前有一种定制页面,就像进度条或其他东西。在启动我的应用程序之前,我如何定制那个不太漂亮的空白页面?!提前准备好 您可以使用启动屏幕进行此操作 工作代码: public class Mainsplash extends Activity { /** Dur

您是否曾在许多应用程序中看到过在启动第一个活动之前出现的页面,不知怎的,它就像一个等待页面?!我是android的初学者,当我点击我的应用程序,首先出现一个空白的白色页面,然后在3秒后主要活动出来。但在许多应用程序中,在第一次活动之前有一种定制页面,就像进度条或其他东西。在启动我的应用程序之前,我如何定制那个不太漂亮的空白页面?!提前准备好

您可以使用启动屏幕进行此操作 工作代码:

public class Mainsplash extends Activity {


     /** Duration of wait **/
    private final int SPLASH_DISPLAY_LENGTH = 3000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splashscreen);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);




        /* New Handler to start the Menu-Activity 
         * and close this Splash-Screen after some seconds.*/
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                /* Create an Intent that will start the Menu-Activity. */
                Intent mainIntent = new Intent(Mainsplash.this,MainActivity.class);
                Mainsplash.this.startActivity(mainIntent);
                Mainsplash.this.finish();
            }
        }, SPLASH_DISPLAY_LENGTH);
    }

}
Xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/load_src"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splashimg"
    android:gravity="center"
    android:orientation="vertical" >

  <RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/ll_v1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
      android:layout_alignParentBottom="true"
         >


        <ProgressBar
            android:id="@+id/prg"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />



    </LinearLayout>
    </RelativeLayout>




</LinearLayout>

也在清单文件中

<activity
            android:name=".Mainsplash"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

使用该启动活动的意图过滤器使其首先启动


希望这对您有所帮助

您可以使用启动屏幕进行此操作 工作代码:

public class Mainsplash extends Activity {


     /** Duration of wait **/
    private final int SPLASH_DISPLAY_LENGTH = 3000;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        this.requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.splashscreen);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);




        /* New Handler to start the Menu-Activity 
         * and close this Splash-Screen after some seconds.*/
        new Handler().postDelayed(new Runnable(){
            @Override
            public void run() {
                /* Create an Intent that will start the Menu-Activity. */
                Intent mainIntent = new Intent(Mainsplash.this,MainActivity.class);
                Mainsplash.this.startActivity(mainIntent);
                Mainsplash.this.finish();
            }
        }, SPLASH_DISPLAY_LENGTH);
    }

}
Xml代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/load_src"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/splashimg"
    android:gravity="center"
    android:orientation="vertical" >

  <RelativeLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"

    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/ll_v1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
      android:layout_alignParentBottom="true"
         >


        <ProgressBar
            android:id="@+id/prg"

            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />



    </LinearLayout>
    </RelativeLayout>




</LinearLayout>

也在清单文件中

<activity
            android:name=".Mainsplash"
            android:label="@string/app_name"
            android:screenOrientation="portrait" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

使用该启动活动的意图过滤器使其首先启动


希望这有帮助

从技术上讲,您正在谈论的东西叫做启动屏幕

启动屏幕用于显示冷启动,我们可以在其中准备好运行应用程序。谷歌主张使用它。

很少有方法显示初始屏幕

  • 您可以像这样使用
    CountDownTimer
    。在
    SplashActivity.java中

    <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>
    
    }.start()

  • 您可以像这样使用
    处理程序
    。在
    SplashActivity.java中

    <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>
    
    },超时)

  • 使用主题-正确的做法

  • 在drawable文件夹中添加
    background\u splash.xml
    文件

    <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>
    
    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>
    
    public class SplashActivity extends AppCompatActivity 
    {
        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
    
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();
        }
    }
    

    从技术上讲,你们正在谈论的东西叫做启动屏幕

    启动屏幕用于显示冷启动,我们可以在其中准备好运行应用程序。谷歌主张使用它。

    很少有方法显示初始屏幕

  • 您可以像这样使用
    CountDownTimer
    。在
    SplashActivity.java中

    <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>
    
    }.start()

  • 您可以像这样使用
    处理程序
    。在
    SplashActivity.java中

    <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>
    
    },超时)

  • 使用主题-正确的做法

  • 在drawable文件夹中添加
    background\u splash.xml
    文件

    <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>
    
    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>
    
    public class SplashActivity extends AppCompatActivity 
    {
        @Override
        protected void onCreate(Bundle savedInstanceState) 
        {
            super.onCreate(savedInstanceState);
    
            Intent intent = new Intent(this, MainActivity.class);
            startActivity(intent);
            finish();
        }
    }
    

    你可以展示闪屏,这可能对Tnx有帮助,我知道了。“我不知道它是什么。”佩德拉米亚兹迪波尔,你说的东西叫斯帕尔什屏幕。请看我的答案,了解不同的方法:)你可以展示闪屏,这可能会对Tnx有所帮助。“我不知道它是什么。”佩德拉米亚兹迪波尔,你说的东西叫斯帕尔什屏幕。请查看我的答案,了解不同的操作方法:)