Android 闪屏安卓

Android 闪屏安卓,android,android-fragments,splash-screen,Android,Android Fragments,Splash Screen,我是初学者,我想展示闪屏,但我的老板想使用Fragment。我不知道如何在我的主要活动中实施它。我知道我必须在时间和堆栈布局中使用处理程序,但我还没有找到方法。 谢谢您不需要处理程序来执行此操作,请执行以下步骤: 1-为启动屏幕创建一个活动,在主活动准备就绪后启动主活动: public class SplashActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedIn

我是初学者,我想展示闪屏,但我的老板想使用Fragment。我不知道如何在我的主要活动中实施它。我知道我必须在时间和堆栈布局中使用处理程序,但我还没有找到方法。
谢谢

您不需要处理程序来执行此操作,请执行以下步骤:

1-为启动屏幕创建一个活动,在主活动准备就绪后启动主活动:

public class SplashActivity extends AppCompatActivity {

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

        Intent intent = new Intent(this, MainActivity.class);
        startActivity(intent);
        finish();
    }
}
2-在pap甚至可以膨胀布局之前,启动屏幕必须准备好,因此我们创建了一个xml文件,并将其定义为窗口的背景,下面是一个带有灰色背景和中间图像的xml文件(称为background_splash.xml):


3-现在进入your 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>

@可绘制/背景\u飞溅
4-最后进入清单文件,将SplashActivity定义为启动器活动,并在其上设置新样式:

<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>

如果要在MainActivity中添加启动屏幕作为片段

  • 将FrameLayout添加到MainActivity中,在FrameLayout内为视图创建布局,并插入一个用于保存SplashScreen显示的片段(确保片段位于MainActivity的底部,以便其显示在布局上)
  • 范例

    <FrameLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent">
    
       <LinearLayout 
          android:layout_width="match_parent"
          android:layout_height="match_parent">
    
             //Your UI goes here        
    
       </LinearLayout>
    
    
      <Fragment
          Your Fragment with Splash Screen Goes here 
       />
    </FrameLayout>
    

    它在android中非常简单,我们只是使用处理程序概念来实现启动屏幕

    在SplashScreenActivity java文件中粘贴此代码。

    public void LoadScreen() {
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {                 
                    Intent i = new Intent(SplashScreenActivity.this, AgilanbuGameOptionsActivity.class);
                    startActivity(i);
                }
            }, 2000); // you can increase or decrease the timelimit of your screen
        }
    
    在SplashScreenActivity xml文件中使用imageview放置任何图片。

    public void LoadScreen() {
            final Handler handler = new Handler();
            handler.postDelayed(new Runnable() {
                @Override
                public void run() {                 
                    Intent i = new Intent(SplashScreenActivity.this, AgilanbuGameOptionsActivity.class);
                    startActivity(i);
                }
            }, 2000); // you can increase or decrease the timelimit of your screen
        }
    
    在Kotlin#Kotlin#Splash#LuanchScreen中

     private fun waitForWhile() {
        Handler(Looper.getMainLooper()).postDelayed({
            callNextActivity()
        }, 3000)
    
    }
    
    private fun callNextActivity() {
        val intent = Intent(this,SignInActivity :: class.java)
        startActivity(intent)
        finish()
    }
    

    你的意思是什么时候启动应用程序?第一个屏幕(布局)显示我恐怕我不明白你的意思:“保存你的SplashScreen显示的片段(确保你的片段位于主活动的底部,以便它显示在你的布局上)”你能详细描述一下吗?
     private fun waitForWhile() {
        Handler(Looper.getMainLooper()).postDelayed({
            callNextActivity()
        }, 3000)
    
    }
    
    private fun callNextActivity() {
        val intent = Intent(this,SignInActivity :: class.java)
        startActivity(intent)
        finish()
    }