赞
踩
- package com.example.administrator.logopage;
-
- import android.animation.Animator;
- import android.animation.AnimatorSet;
- import android.animation.TimeInterpolator;
- import android.app.Activity;
- import android.content.Intent;
- import android.content.pm.PackageInfo;
- import android.content.pm.PackageManager;
- import android.graphics.PixelFormat;
- import android.os.Handler;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.WindowManager;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.Animation;
- import android.view.animation.AnimationSet;
- import android.widget.ImageView;
- import android.widget.TextView;
-
- public class MainActivity extends Activity {
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- new Handler().postDelayed(new Runnable() {
- public void run() {
- /* Create an Intent that will start the Main WordPress Activity. */
- Intent mainIntent = new Intent(MainActivity.this, Main2Activity.class);
- MainActivity.this.startActivity(mainIntent);
- MainActivity.this.finish();
- }
- }, 3000);
- }
-
- }
在跳转到的Main2Activity中添加按键监听
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode==KeyEvent.KEYCODE_BACK){
- Intent i= new Intent(Intent.ACTION_MAIN); //主启动,不期望接收数据
-
- i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //新的activity栈中开启,或者已经存在就调到栈前
-
- i.addCategory(Intent.CATEGORY_HOME); //添加种类,为设备首次启动显示的页面
-
- startActivity(i);
- }
- return super.onKeyDown(keyCode, event);
- }
按下返回就会跟按下home键操作一致,效果自行尝试。
- package com.example.administrator.logopage;
-
- import android.app.Activity;
- import android.content.Intent;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.KeyEvent;
- import android.view.View;
- import android.view.animation.AlphaAnimation;
- import android.view.animation.Animation;
- import android.widget.LinearLayout;
-
- public class Main2Activity extends Activity {
- LinearLayout linearLayout;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main2);
- AlphaAnimation animation=new AlphaAnimation(1.0f,1.0f);
- animation.setDuration(2000);
- linearLayout= (LinearLayout) findViewById(R.id.ll);
- linearLayout.setAnimation(animation);
- animation.setAnimationListener(new Animation.AnimationListener() {
- @Override
- public void onAnimationStart(Animation animation) {
- linearLayout.setVisibility(View.VISIBLE);
- }
-
- @Override
- public void onAnimationEnd(Animation animation) {
- linearLayout.setVisibility(View.GONE); //隐藏起来,不需要任何布局空间
- }
-
- @Override
- public void onAnimationRepeat(Animation animation) {
- //linearLayout.setVisibility(View.GONE);
- }
- }
- );
- }
-
- @Override
- public boolean onKeyDown(int keyCode, KeyEvent event) {
- if (keyCode==KeyEvent.KEYCODE_BACK){
- Intent i= new Intent(Intent.ACTION_MAIN); //主启动,不期望接收数据
-
- i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); //新的activity栈中开启,或者已经存在就调到栈前
-
- i.addCategory(Intent.CATEGORY_HOME); //添加种类,为设备首次启动显示的页面
-
- startActivity(i);
- }
- return super.onKeyDown(keyCode, event);
- }
- }
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout
- android:orientation="vertical"
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:paddingBottom="@dimen/activity_vertical_margin"
- android:paddingLeft="@dimen/activity_horizontal_margin"
- android:paddingRight="@dimen/activity_horizontal_margin"
- android:paddingTop="@dimen/activity_vertical_margin"
- tools:context="com.example.administrator.logopage.Main2Activity">
- <LinearLayout
- android:orientation="vertical"
- android:id="@+id/ll"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@mipmap/ic_launcher">
- </LinearLayout>
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="过来了"/>
- </LinearLayout>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。