手机卫士学习 01-设置启动界面UI

本文详细介绍了一款名为“手机卫士”的应用启动页的设计与实现过程,包括创建工程、设置布局文件、动态获取并显示APK版本信息等关键技术点。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

制作效果如图:


1    创建工程  应用名称:手机卫士    工程名称:MoblieSafe    第一个Activitry:SplashActivity 
2    设置布局文件,activity_splash.xml,设置背景图片,设置版本信息,设置进度条
3    动态获取apk版本信息--版本号设置到界面


activity_splash.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/luncher_bg"
    tools:context="com.itheima.mobilesafe.SplashActivity" >

    <TextView
        android:id="@+id/tv_splash_version"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:shadowColor="#ff0000"
        android:shadowDx="1"
        android:shadowDy="1"
        android:shadowRadius="1"
        android:text="版本号1.0"
        android:textColor="#000000"
        android:textSize="20sp" />

    <ProgressBar
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_splash_version"
        android:layout_centerHorizontal="true" />

</RelativeLayout>


SplashActivity.java


package com.itheima.mobilesafe;

import android.app.Activity;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.widget.TextView;


public class SplashActivity extends Activity {
	
	private TextView tv_splash_version;
	
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splash);
        tv_splash_version =(TextView) findViewById(R.id.tv_splash_version);
        tv_splash_version.setText("版本号"+getVersionName());
    }
    /**
     * 得到应用程序的版本名称
     * @return 版本名称
     */
    private String getVersionName(){
    	//apk管理者
    	PackageManager pm = getPackageManager();
    	try {
    		//apk功能清单文件信息
			PackageInfo info = pm.getPackageInfo(getPackageName(), 0);
			return info.versionName;
		} catch (NameNotFoundException e) {
			e.printStackTrace();
			return "";
		}
    }


}


清单文件:


<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.itheima.mobilesafe"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="10"
        android:targetSdkVersion="16" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".SplashActivity"
            android:label="@string/app_name"
            android:theme="@android:style/Theme.Light.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>




源码下载:http://yunpan.cn/cyRPy5ratJxLQ  访问密码 90ac


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值