ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
手机安全卫士项目是跟着黑马的视频做的。 splash是飞洒、飞溅的意思,主要是用于完成一个产品logo显示,期间可以: 1. 后台完成数据库初始化的操作 1. 联网访问服务器,获取服务器最新信息(升级提示) 1. 不同的日期显示出来不同logo,判断当前系统时间,素材一般从服务器上下载下来. 1. 判断时间,根据不同时间显示不同的加载页面 ### 布局文件:splash.xml ~~~ <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/logo2" android:gravity="center_horizontal" android:orientation="vertical" android:id="@+id/ll_splash_main" > <TextView android:layout_marginTop="320dip" android:id="@+id/tv_splash_version" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textColor="#FFff5f00" android:textSize="20sp" android:text="版本号" /> <ProgressBar android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginTop="20dip" /> </LinearLayout> ~~~ ### activity:SplashActivity ~~~ package com.liuhao.mobilesafe.ui; import com.liuhao.mobilesafe.R; import android.os.Bundle; import android.app.Activity; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.view.Menu; import android.view.Window; import android.view.WindowManager; import android.view.animation.AlphaAnimation; import android.widget.LinearLayout; import android.widget.TextView; public class SplashActivity extends Activity { private TextView tv_splash_version; private LinearLayout ll_splash_main; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //取消标题栏 requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.splash); tv_splash_version = (TextView) this.findViewById(R.id.tv_splash_version); ll_splash_main = (LinearLayout) this.findViewById(R.id.ll_splash_main); String versiontext = getVersion(); tv_splash_version.setText(versiontext); /* AlphaAnimation类:透明度变化动画类 * AlphaAnimation类是Android系统中的透明度变化动画类,用于控制View对象的透明度变化,该类继承于Animation类。 * AlphaAnimation类中的很多方法都与Animation类一致,该类中最常用的方法便是AlphaAnimation构造方法。 * * public AlphaAnimation (float fromAlpha, float toAlpha) 参数说明 fromAlpha:开始时刻的透明度,取值范围0~1。 toAlpha:结束时刻的透明度,取值范围0~1。 */ AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f); aa.setDuration(2000); //Animation类的方法,设置持续时间 ll_splash_main.startAnimation(aa); //设置动画 //完成窗体的全屏显示 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.splash, menu); return true; } /** * 获取当前程序的版本号 * @return */ private String getVersion(){ // 获取一个PackageManager的实例,从而可以获取全局包信息 PackageManager manager = getPackageManager(); try { // Retrieve overall information about an application package that is installed on the system. PackageInfo info = manager.getPackageInfo(getPackageName(), 0); // The version name of this package, as specified by the <manifest> tag's versionName attribute. return info.versionName; } catch (Exception e) { e.printStackTrace(); return "版本号未知"; } } } ~~~ ### 相关知识点: 在开发程序是经常会需要软件全屏显示、自定义标题(使用按钮等控件)和其他的需求,今天这一讲就是如何控制Android应用程序的窗体显示. 首先介绍一个重要方法那就是requestWindowFeature(featrueId),它的功能是启用窗体的扩展特性。参数是Window类中定义的常量。 一、枚举常量 > 1.DEFAULT_FEATURES:系统默认状态,一般不需要指定 > 2.FEATURE_CONTEXT_MENU:启用ContextMenu,默认该项已启用,一般无需指定 > 3.FEATURE_CUSTOM_TITLE:自定义标题。当需要自定义标题时必须指定。如:标题是一个按钮时 > 4.FEATURE_INDETERMINATE_PROGRESS:不确定的进度 > 5.FEATURE_LEFT_ICON:标题栏左侧的图标 > 6.FEATURE_NO_TITLE:无标题 > 7.FEATURE_OPTIONS_PANEL:启用“选项面板”功能,默认已启用。 > 8.FEATURE_PROGRESS:进度指示器功能 > 9.FEATURE_RIGHT_ICON:标题栏右侧的图标 **效果图: **default: DEFAULT_FEATURES ![](https://box.kancloud.cn/2016-02-18_56c5a94ee3419.png) progress:FEATURE_PROGRESS:进度指示器功能 ![](https://box.kancloud.cn/2016-02-18_56c5a94f09a4f.png) no title:FEATURE_NO_TITLE:无标题 ![](https://box.kancloud.cn/2016-02-18_56c5a94f24101.png) lefticon:FEATURE_LEFT_ICON:标题栏左侧的图标 ![](https://box.kancloud.cn/2016-02-18_56c5a94f322d8.png) fullscreen: ![](https://box.kancloud.cn/2016-02-18_56c5a94f43bdb.png) indeterminate_progress: FEATURE_INDETERMINATE_PROGRESS:不确定的进度 ![](https://box.kancloud.cn/2016-02-18_56c5a94f57116.png) customtitle:FEATURE_CUSTOM_TITLE:自定义标题。 ![](https://box.kancloud.cn/2016-02-18_56c5a94f66de6.png) AlphaAnimation类是Android系统中的透明度变化动画类,用于控制View对象的透明度变化,该类继承于Animation类。AlphaAnimation类中的很多方法都与Animation类一致,该类中最常用的方法便是AlphaAnimation构造方法。 【基本语法】public AlphaAnimation (float fromAlpha, float toAlpha) 参数说明 fromAlpha:开始时刻的透明度,取值范围0~1。 toAlpha:结束时刻的透明度,取值范围0~1。 ### 运行 [![image](https://box.kancloud.cn/2016-02-18_56c5a94f7b244.jpg "image")](http://img.blog.csdn.net/20140925143019612) [![image](https://box.kancloud.cn/2016-02-18_56c5a94f8ba54.jpg "image")](http://img.blog.csdn.net/20140925143020673) 运行效果: [![Screenshot_2014-09-25-14-32-55](https://box.kancloud.cn/2016-02-18_56c5a94fabeb7.jpg "Screenshot_2014-09-25-14-32-55")](http://img.blog.csdn.net/20140925143206534)