1. 程式人生 > >Android程式的目錄結構分析——manifests目錄、Java目錄、res目錄

Android程式的目錄結構分析——manifests目錄、Java目錄、res目錄

  1. manifests目錄

該目錄下的AndroidManifests.xml檔案是專案的系統配置檔案,又叫做清單檔案,每個專案都必須含有該檔案。它為Android系統提供了啟動執行專案時必須的基本資訊。

  • 應用程式包名稱
  • 應用程式申請的自身所需要的許可權
  • 應用程式中包含的元件
<?xml version="1.0" encoding="utf-8"?>==檔案序言資訊==
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.v8.item1">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
    
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".SecondActivity"/>
        <receiver android:name=".MyBroadcastReceiver">
        	<intent-filter>
        		<action android:name="com.example.v8.item1.mybroadcastreceiver"/>
        		<categroy/>            		
        	</intent-filter>
        </receiver>
        <provider android:authorities="com.example.v8.item1.mycontentprovider" android:name=".MyContentProvider">
        
        </provider>
    </application>
</manifest>

裝置允許備份 android:allowBackup=“true” 定義應用程式的圖示 android:icon="@mipmap/ic_launcher" @mipmap/ic_launcher資源引用方式標誌著圖示是存放在/res/mipmap目錄下的資原始檔中,資原始檔的名稱為ic_lanucher android:supportsRtl=“true"設定應用程式支援RTL佈局,此屬性只有在API17之後生效。 android:theme=”@style/AppTheme">應用程式的主題是AppTheme 標籤下定義的<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />用於宣告Activity是應用程式啟動時,首先被執行的Activity。 如果使用者建立一個Activity就必須在AndroidManifests.xml檔案下新增該Activity的資訊,否則應用程式無法識別。 <service>標籤用於新建一個服務類MyService ContentProvider元件採用<provider>標籤 android系統限定網路系統資源的使用,使用時必須向Android系統申請許可權,申請的方式:在AndroidManifests.xml
檔案的<manifests>標籤下新增<use-permission android:name="許可權"/> 許可權可查閱

  1. Java目錄

原始碼目錄,所有使用者新增的或者允許使用者修改的Java原始檔都存放在這裡

  1. res目錄

資源目錄包含本專案使用的所有資原始檔。該目錄下的子目錄:

  • drawable主要存放一些使用者自定義的形狀和背景選擇器。都是xml型別的。背景選擇器用於改變ListView或者button等控制元件的背景顏色。
  • layout存放介面佈局檔案。
  • mipmap包含應用程式的原生圖示檔案強烈建議使用mipmap存放圖片檔案,可以提高系統渲染圖片的速度,提高圖片的質量,減輕CPU的壓力。
  • value存放xml檔案的資源描述檔案,包含顏色(colors.xml),尺寸(dimens.xml),字串(string.xml),樣式(styles.xml)。

Android對資源名稱有約束,命名只能使用字母數字下劃線和點不能以數字開頭,否則會編譯錯誤。