安卓项目实现闪屏的功能

来源:互联网 发布:淘宝评价多长时间消失 编辑:程序博客网 时间:2024/06/03 19:29

方法1:在主文件中写入

<span style="font-size:14px;">  // 取消标题          this.requestWindowFeature(Window.FEATURE_NO_TITLE);          // 取消状态栏          this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                  WindowManager.LayoutParams.FLAG_FULLSCREEN);  </span>

方法2:可以在AndroidManifest.xml配置文件中修改显示的状态

<span style="font-size:14px;"> <activity  android:name="com.example.walkerlogin1.WelcomeActivity"            android:label="@string/app_name"            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"            >                </activity></span>


具体实现代码如下:

package com.example.walkerlogin1;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.animation.AlphaAnimation;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;import android.widget.RelativeLayout;public class WelcomeActivity extends Activity {protected void onCreate(Bundle savedInstanceState) {   super.onCreate(savedInstanceState);               // 取消标题               this.requestWindowFeature(Window.FEATURE_NO_TITLE);          // 取消状态栏             this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,                  WindowManager.LayoutParams.FLAG_FULLSCREEN);  setContentView(R.layout.activity_welcome);  RelativeLayout layoutWelcome=(RelativeLayout) findViewById(R.id.activity_welcome);  AlphaAnimation alphaAnimation=new AlphaAnimation(0.1f,1.0f);   alphaAnimation.setDuration(3000);   layoutWelcome.startAnimation(alphaAnimation);  alphaAnimation.setAnimationListener(new AnimationListener() {    public void onAnimationStart(Animation animation) { }      public void onAnimationRepeat(Animation animation) { }     public void onAnimationEnd(Animation animation) { System.out.println("你好");Intent  intent=new Intent(WelcomeActivity.this,GuideActivity.class);     startActivity(intent);  } });  }}

配置文件修改也可:

<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.walkerlogin1"    android:versionCode="1"    android:versionName="1.0" >    <uses-sdk        android:minSdkVersion="8"        android:targetSdkVersion="17" />    <application        android:allowBackup="true"        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/AppTheme" >              <activity  android:name="com.example.walkerlogin1.MainActivity"            android:label="@string/app_name"></activity>         <activity  android:name="com.example.walkerlogin1.WelcomeActivity"            android:label="@string/app_name"            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"            >             <intent-filter>                <action android:name="android.intent.action.MAIN" />//取消标题栏                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>                 </activity>             </application></manifest>

UI布局代码activity_welcome.xml


<RelativeLayout 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:background="@drawable/welcome_bg"    tools:context=".WelcomeActivity"     android:id="@+id/activity_welcome"></RelativeLayout>


1 0