1. 程式人生 > >Android小專案之三 splash介面

Android小專案之三 splash介面

------- 源自夢想永遠是你IT事業的好友、只是勇敢地說出我學到! ----------

按慣例,寫在前面的:可能在學習Android的過程中,大家會和我一樣,學習過大量的基礎知識,很多的知識點也都能說出了123來,但是這些孤立的點終究顯得太零散了,因此,我想從今天開始,以最經典的手機安全衛士專案為例,自己鍛鍊一下,也是想和大家交流交流,希望大家都能給出見解,共同進步

三、splash介面


1.工程mobilesafe
最低相容版本設為2.2(很多公司都2.3了)
使用4.1編譯
2.splashActivity
一般軟體都會有這樣一個介面
3.splash介面的作用:
1展示產品的logo,提升產品的知名度(腦殘的廣告很可能提高知名度)
2應用程式的初始化操作、讀取配置檔案、載入設定
3連線伺服器,獲取最新資訊,檢查版本號
4聯網校驗檢查引用程式的完整性

4.做出splash介面佈局
使用RelativeLayout佈局。
1設定背景圖片。
android:background="@drawable/splash_main_bg"
2預覽介面去主題
選擇Theme,選Theme.Black.NoTitleBar
這樣的配置並不會生效,若想生效,要到清單檔案裡面配置
3清單檔案中去主題

在activity標籤下加

android:theme="@android:style/Theme.Black.NoTitleBar"
4介面最中間放版本號
TextView
命名規範:id:控制元件型別_在哪個介面_功能
陰影效果:android:shadowColor
  android:shadowDx
 android:shadowDy

具體程式碼:
<TextView
					android:shadowColor="#ffffff"
					android:shadowDx="3"
					android:shadowDy="3"
					android:shadowRadius="3"
					android:id="@+id/tv_splash_version"
					android:layout_width="wrap_content"
					android:layout_height="wrap_content"
					android:layout_centerHorizontal="true"
					android:layout_centerVertical="true"
					android:textColor="#000000"
					android:textSize="16sp"
					android:text="版本號:"/>

報出錯誤:這裡我們可以把它忽略掉
The graphics preview in the layout editor may not be accurate:
Paint.setShadowLayer is not supported. (Ignore for this session)
5版本號下方放進度條
具體程式碼:
<ProgressBar 
					android:layout_width="wrap_content"
					android:layout_height="wrap_content"
					android:layout_centerHorizontal="true"
					android:layout_below="@id/tv_splash_version"/>

5.我們現在需要改變版本號中的內容

版本號是在清單檔案中設定的,我們要定義一個方法,獲取清單檔案中的版本號。
用到PackageManager、PackageInfo類。
定義方法getVersion(),獲取版本號
具體程式碼:
private String getVersion() {
				try {
					PackageManager pm = getPackageManager();
					PackageInfo packInfo = pm.getPackageInfo(getPackageName(), 0);
					return packInfo.versionName;
				} catch (NameNotFoundException e) {
					e.printStackTrace();
					//cannot reach
					return "";
				}
			}


然後
tv_splash_version.setText("版本號:"+getVersion());


便可獲取清單檔案中的版本號並設在佈局中的TextView中。
------- 源自夢想永遠是你IT事業的好友、只是勇敢地說出我學到! ----------