如何在android中使用跳过按钮逐个显示两个启动画面

时间:2016-07-19 05:31:16

标签: android

我是android新手。我想在底部用跳过按钮一个接一个地显示两个闪屏。当用户按下跳过按钮时,它将重定向到主页活动..任何人都可以告诉我如何做到这一点......?我真的很感激..我知道如何显示单个闪屏:

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

        /*
         * Showing splash screen with a timer. This will be useful when you
         * want to show case your app logo / company
         */

        @Override
        public void run() {
            // This method will be executed once the timer is over
            // Start your app main activity
            Intent i = new Intent(SplashScreen.this, PushNotificationMainActivity.class);
            startActivity(i);

            // close this activity
            finish();
        }
    }, SPLASH_TIME_OUT);
}

但是我想要两个闪屏...我可以做..?

6 个答案:

答案 0 :(得分:1)

您可以做的是创建// it will check if ABC is there in array `people.name` if($.inArray("ABC", people.name) !== -1) { people.push({name: "testing"}); } 显示第二个屏幕,用户按下跳过按钮,然后显示 MainActivity

Handler

第二个屏幕与上面相同

  

当用户按下跳过按钮

final android.os.Handler  handler = new android.os.Handler();


        final Runnable runnable=new Runnable() {
            @Override
            public void run() {

                // go to next screen (second screen in queue)

            }
        };

    handler.postDelayed(runnable,SPLASH_TIME_OUT);

答案 1 :(得分:1)

这是您问题的最简单的解决方案。

  public class MainActivity extends AppCompatActivity {

        Runnable runnable;
        private Handler handler;

        public static Intent getIntent(Context context, boolean path) {
            Intent filesIntent = new Intent(context, MainActivity.class);
            filesIntent.putExtra("splash", path);
            return filesIntent;
        }

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            final boolean b = getIntent().getBooleanExtra("splash", false);
            if(b){
                setContentView(R.layout.activity_main1);
            } else {
                setContentView(R.layout.activity_main);
            }

            Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
            setSupportActionBar(toolbar);

            handler = new Handler();

            runnable = new Runnable() {
                @Override
                public void run() {
                    if(b){
                        handler.removeCallbacks(runnable);
                        startActivity(new Intent(getApplicationContext(), HomeActivity.class));
                        finish();
                    } else {
                        startActivity(MainActivity.getIntent(MainActivity.this, true));
                        finish();
                    }
                }
            };

            handler.postDelayed(runnable, 3000);
        }

        public void buttonSkip(View view) {
            handler.removeCallbacks(runnable);
            startActivity(new Intent(getApplicationContext(), HomeActivity.class));
            finish();
        }
    }

如果您有任何疑问,请对此发表评论......:)

答案 2 :(得分:0)

创建两个屏幕1& 2将按钮跳到屏幕1上,然后单击将其重定向到第二个屏幕并在屏幕2上放置跳过按钮,同时单击跳过,您可以将其重定向到您想要的位置。

你可以在点击按钮中使用它,这样它就会移动到你想要的屏幕。

Intent i = new Intent(SplashScreen.this, PushNotificationMainActivity.class);
startActivity(i);

答案 3 :(得分:0)

public class MainActivity extends Activity {

    public static final int Tick = 1000; // change view after five second ok
    public static final int Complete = 10000;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        new CountDownTimer(Complete, Tick) {

            public void onTick(long millisUntilFinished) {
                if (millisUntilFinished < (Complete / 2)) {
                    Toast.makeText(MainActivity.this, "Layout no 2 Visible", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(MainActivity.this, "Layout no 1 Visible", Toast.LENGTH_SHORT).show();
                }
            }

            public void onFinish() {
                Toast.makeText(MainActivity.this, "go to next activity", Toast.LENGTH_SHORT).show();
            }
        }.start();

    }
}

答案 4 :(得分:0)

如果你知道如何在计时器结束时调用下一个活动,你可以使用以下逻辑:

考虑两个屏幕上的跳过按钮 -

<强> SplashActivityOne

在意图中,调用SplashActivityTwo(在计时器结束后)

如果单击跳过按钮 - 停止计时器(handler.removeCallbacks) - 调用HomeActivity

<强> SplashActivityTwo

在意图中,调用HomeActivity(在计时器结束后)

如果单击跳过按钮 - 停止计时器(handler.removeCallbacks) - 调用HomeActivity

答案 5 :(得分:0)

在布局文件中添加一个跳过按钮

Button button = (Button)findViewById(R.id.skip);button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
    Intent i = new Intent(SplashScreen.this, PushNotificationMainActivity.class);
        startActivity(i);

        // close this activity
        finish();
}});