【问题标题】:How to stop a Splash Screen with a click before the end?如何在结束前通过单击停止启动画面?
【发布时间】:2013-05-19 17:24:30
【问题描述】:

我在我的应用程序中创建了一个活动启动画面。

这与动画效果很好是我的代码:

public class SpalshScreenActivity extends Activity {
 private static final int STOPSPLASH = 0;
 private static final long SPLASHTIME = 3000;
 private boolean flagBack = false;

 private final transient Handler splashHandler = new Handler() {
    @Override
    public void handleMessage(Message msg) {
        if (msg.what == STOPSPLASH && !flagBack) {
            StartMainActivity();
        }
        super.handleMessage(msg);
    }
 };

 public void onAttachedToWindow() {
    super.onAttachedToWindow();
    Window window = getWindow();
    window.setFormat(PixelFormat.RGBA_8888);
 }

 @Override
 public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setTheme(R.style.HideActionBar);
    setContentView(R.layout.splash);
    StartAnimations();
    final Message msg = new Message();
    msg.what = STOPSPLASH;
    splashHandler.sendMessageDelayed(msg, SPLASHTIME);
 }

 private void StartAnimations() {
    Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
    anim.reset();
    LinearLayout l=(LinearLayout) findViewById(R.id.lin_lay);
    l.clearAnimation();
    l.startAnimation(anim);

    anim = AnimationUtils.loadAnimation(this, R.anim.translate);
    anim.reset();
    ImageView iv = (ImageView) findViewById(R.id.logo);
    iv.clearAnimation();
    iv.startAnimation(anim);
 }

 private void StartMainActivity() {
    final Intent intent = new Intent(SpalshScreenActivity.this, MainFragmentActivity.class);
    startActivity(intent);
    finish();
 }

 public boolean onKeyDown(int keyCode, KeyEvent evt) {  
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        flagBack = true;
        finish();
        return true;
    }
    return false;
 }}

现在我想添加点击屏幕以停止 SplashScreen 的功能。

我尝试过这种方式,它有效,但我认为这不是最佳解决方案(慢):

@Override
public boolean onTouchEvent(MotionEvent evt) {
    if(evt.getAction() == MotionEvent.ACTION_DOWN) {
        flagBack = true;
        StartMainActivity();
    }
    return true;
}

提前谢谢你!

【问题讨论】:

  • 只需为 imageview 设置 onclicklistener 并在里面调用你调用的任何内容来结束启动画面。
  • 提示:Android 设计指南建议不要使用闪屏。 developer.android.com/design/patterns/help.html
  • 感谢您提供此信息@EGHDK。你知道为什么吗?
  • @lopez.mikhael 它写在“为您的应用程序设计帮助”部分下。基本上,用户获得 SplashScreen 很烦人/或者它没用。通常,用户能够通过自己的方式发现应用程序的功能。但这些只是建议。
  • 设计指南只是“指南”,但是是的,我建议只向用户显示一次启动画面,但每次用户打开应用程序时,他们都会喜欢它的速度它加载。不要仅仅因为可以就使用闪屏,使用闪屏做一些有意义的事情。

标签: java android splash-screen


【解决方案1】:

使用与 onTouchEvent 中相同的代码为活动设置 OnClickListener

【讨论】:

    猜你喜欢
    • 2020-06-05
    • 2014-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多