【问题标题】:Creating a splash screen in Android studio Version 2.2在 Android Studio 2.2 版中创建启动画面
【发布时间】:2017-07-12 13:49:43
【问题描述】:

似乎找不到帮助我为我在 android studio 中完成的 android 项目创建启动画面的指南。

(我正在使用 mac)

我找不到在哪里添加新活动,因此我可以创建启动屏幕。

编辑:无法从我被告知尝试的区域中找到:下面的照片 SecondEDIT:这是一个 React-Native 项目

Picture 1

picture2

【问题讨论】:

  • 我猜你是在点击资源文件夹。您应该点击 app>src>com.yourpackagename。
  • @SripadRaj 是对的
  • 您可以使用 src-main->Java -> Package 添加新活动

标签: android android-studio android-activity react-native splash-screen


【解决方案1】:

你可以这样做:

然后将新活动设置为启动器活动并使用处理程序,在延迟后设置下一个活动:

 new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent nextIntent = new Intent(mContext, HomeActivity.class);
            startActivity(nextIntent);
            finish();
        }
    }, 1000); //1000ms = 1second

【讨论】:

  • @DominicGozza 因此,当您在 android studio 中时,只需单击屏幕左上角的文件,然后单击新建 -> 活动 -> 空活动,然后您将添加一个新活动到您的项目,就像你的问题一样
  • @DominicGozza 在 android studio 左侧的项目结构窗格中,点击“app”文件,然后按照上面的说明进行操作
  • 查看上图1!请!
  • @DominicGozza 检查上面的评论
  • 对不起。我的意思是图片 1 而不是 2。
【解决方案2】:

只需在你的一些包中创建一个类,为其创建一个布局文件并将其添加到 mainfest 下的应用程序标签下,你可以通过以下方式获得 Splash 类型的功能:

public class SplashActivity extends AppCompatActivity {

private static final long SPLASH_SCREEN_DELAY = 2000;

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

    CountDownTimer countDownTimer = new CountDownTimer(SPLASH_SCREEN_DELAY, 1000) {
        @Override
        public void onTick(long l) {

        }

        @Override
        public void onFinish() {

            User user = GeneralUtils.getRegisteredUser(SplashActivity.this);
            if (user == null || user.getUserId() == null) {
                Intent intent = new Intent(SplashActivity.this, WalkThroughActivity.class);
                startActivity(intent);
            } else {
                Intent intent = new Intent(SplashActivity.this, MainActivity.class);
                startActivity(intent);
            }

            SplashActivity.this.finish();

        }
    };

    countDownTimer.start();
}

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-07-01
    • 2016-02-26
    • 2012-12-29
    • 1970-01-01
    • 1970-01-01
    • 2023-02-02
    • 1970-01-01
    • 2020-02-27
    相关资源
    最近更新 更多