使用資源管理工具管理應用程式的 UI 資源'
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
「Resource Manager」是一個工具視窗,可用於在應用程式中匯入、建立、管理及使用資源。如要開啟這個視窗,請在選單內依序選取「View」>「Tool Windows」>「Resource Manager」,或選取左側列中的「Resource Manager」。

圖 1 「Resource Manager」工具視窗。
- 按一下「Add」圖示
,即可在專案中加入新資源。您可以新增圖片素材資源、向量素材資源、字型、資源檔案和值,也可以匯入可繪項目到專案。
- 選取模組,即可查看該模組專屬的資源。
- 使用搜尋列,即可搜尋專案內所有模組的資源。
- 依據資源管理工具中的類型顯示資源。您可以利用這些分頁切換資源類型。按一下溢位圖示
,即可顯示其他資源類型。
- 點選篩選器按鈕,即可篩選本機相依模組、外部程式庫和 Android 架構的所列資源。您也可以使用篩選器顯示主題屬性。
- 在主要內容區域中預覽資源。在資源上按一下滑鼠右鍵,即可查看內容選單。透過這個選單,您可以重新命名資源,以及搜尋應用程式中使用資源的位置。
- 按一下這些按鈕,就能以圖塊或清單的形式查看資源。
- 按一下這些按鈕,即可變更資源的預覽大小。
除了上述功能外,資源管理工具也能讓您大量匯入可繪項目到專案中。如要大量匯入,您可以採取下列其中一種做法:
- 將 SVG 等圖片檔直接拖曳到資源管理工具。
- 使用「Import Drawables」精靈。
詳情請參閱「在專案中匯入可繪項目」一節。
如要查看更多詳細資訊,請在資源管理工具中按兩下任一資源。如果資源有多個版本,這個詳細資料檢視畫面會顯示每個版本以及任何相關聯的限定詞,如圖 2 所示。在此處按兩下特定版本,即可在編輯器視窗中開啟。

圖 2. 資源管理工具顯示不同螢幕密度的圖片資源版本。
在專案中匯入可繪項目
您可以使用資源管理工具,將圖片資源匯入專案。如需支援的圖片類型清單,請參閱「圖片支援」。
如要在專案中匯入圖片資源,請按照下列步驟操作:
將圖片直接拖曳到 Android Studio 中的「Resource Manager」視窗。
- 您也可以採取以下做法:
- 按一下加號圖示 +。
- 選擇「Import Drawables」,如圖 3 所示。
- 選取要匯入的檔案和資料夾。

圖 3. 從選單中選取「Import Drawables」。
畫面上會出現「Import Drawables」對話方塊,如圖 4 所示。這個對話方塊會顯示一份清單,列出您要匯入的資源。如要重新命名資源,請點選資源預覽上方的文字方塊。
如果想提供同一資源的多個版本,請新增裝置設定限定詞 (詳情請見下一節),說明每項資源支援的特定設定。
舉例來說,如要針對不同螢幕密度提供同一資源的多個版本,可以為各版本新增像素密度限定詞。請注意,如有兩個以上資源的名稱和限定詞相同,系統只會匯入一個版本。
如要進一步瞭解資源限定詞,請參閱「提供額外資源」。

圖 4. 「Import Drawables」對話方塊。
命名資源並新增所有必要的限定詞後,請按一下「Next」。
下一個畫面會顯示匯入資源的摘要。準備好要匯入時,請按一下「Import」。
「Resource Manager」視窗中現在會顯示可用於專案的資源,如圖 5 所示。

圖 5. 資源管理工具現在會顯示您匯入的圖片。
自動剖析可繪項目密度
當您匯入檔案或資料夾時,如果路徑中包含像素密度限定詞,資源管理工具會在匯入期間自動套用這類限定詞。資源管理工具可剖析 Android 像素密度限定詞,以及 iOS 縮放比例係數。
下表列出 Android 和 iOS 所支援不同密度的表示方式:
密度 |
Android 像素密度限定詞 |
iOS 縮放比例係數 |
低密度 (約 120 dpi) |
ldpi |
不支援 |
中密度 (約 160 dpi) |
mdpi |
原始縮放比例 |
高密度 (約 240 dpi) |
hdpi |
不支援 |
超高密度 (約 320 dpi) |
xhdpi |
@2x |
特別超高密度 (約 480 dpi) |
xxhdpi |
@3x |
極致超高密度 (約 640 dpi) |
xxxhdpi |
@4x |
以下列舉幾個例子,說明輸入路徑在匯入後如何轉換為資源路徑:
- Android 像素密度限定詞:
hdpi
- 輸入路徑: /UserFolder/icon1/hdpi/icon.png
資源路徑: <projectFolder>/<moduleFolder>/src/main/res/drawable-hdpi/icon.png
- Android 像素密度限定詞:
xxhdpi
- 輸入路徑: /UserFolder/icon1/abc-xxhdpi/icon.png
資源路徑: <projectFolder>/<moduleFolder>/src/main/res/drawable-xxhdpi/icon.png
- iOS 縮放比例係數:@2x
- 輸入路徑: /UserFolder/icon1/icon@2x.png
資源路徑: <projectFolder>/<moduleFolder>/src/main/res/drawable-xhdpi/icon.png
- iOS 縮放比例係數:@2x
- 輸入路徑: /UserFolder/icon1/icon@2x_alternate.png
資源路徑: <projectFolder>/<moduleFolder>/src/main/res/drawable-xhdpi/icon_alternate.png
如要進一步瞭解如何支援具有不同像素密度的裝置,請參閱「支援不同的像素密度」。
將可繪項目拖曳到版面配置中
您可以直接將資源管理工具中的可繪項目拖曳到版面配置上。當您將資源拖曳到版面配置時,資源管理工具會為該可繪項目建立對應的 ImageView
,如動畫 1 所示:

動畫 1:將可繪項目拖曳到「Design」檢視畫面中的版面配置上。
您也可以直接將資源拖曳到版面配置的 XML 上,如動畫 2 所示:

動畫 2:在「Text」檢視畫面中,將可繪項目拖曳到版面配置上。
將可繪項目拖曳到「Text」分頁中的版面配置時,產生的程式碼會因該項目在版面配置中的位置而不同:
- 如果您將可繪項目拖曳到空白區域,資源管理工具會產生對應的
ImageView
。
- 如果您將可繪項目拖曳到版面配置 XML 中的任何屬性上,資源管理工具會將該屬性值替換成可繪項目參照。您也可以拖曳任何其他資源類型至 XML 屬性,取代屬性值。
- 如果您將可繪項目拖曳到現有
ImageView
元素上,資源管理工具會替換對應的來源屬性。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。Java 與 OpenJDK 是 Oracle 和/或其關係企業的商標或註冊商標。
上次更新時間:2025-07-27 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-07-27 (世界標準時間)。"],[],[],null,["# Manage your app's UI resources with Resource Manager\n\nResource Manager is a tool window for importing, creating, managing, and\nusing resources in your app. To open the tool window, select\n**View \\\u003e Tool Windows \\\u003e Resource Manager** from the menu or select\n**Resource Manager** in the left side bar.\n\n**Figure 1.** The Resource Manager tool window.\n\n1. Click **Add** to add a new resource to your project. You can add image assets, vector assets, fonts, or resource files and values, or you can [import drawables](#import) into your project.\n2. Select a module to view resources specific to that module.\n3. Search for a resource across all modules in your project using the search bar.\n4. Display your resources according to [type](/guide/topics/resources/available-resources) in the Resource Manager. Use these tabs to switch between resource types. Click the overflow icon to show additional resource types.\n5. Filter the displayed resources from local dependent modules, external libraries, and the Android framework using the filter button. You can also use the filter to show theme attributes.\n6. Preview your resources in the main content area. Right-click a resource to see a context menu where you can rename the resource and search your app for where the resource is used.\n7. Click these buttons to view your resources as either tiles or lists.\n8. Click these buttons to change the preview size of your resources.\n\nIn addition to these features, the Resource Manager provides a\nway to bulk-import drawables into your project. To bulk-import, you can either:\n\n- Drag your image files---including SVG files---directly onto the Resource Manager.\n- Use the **Import Drawables** wizard.\n\nFor more information, see the [Import drawables into your project](#import)\nsection.\n\nTo see more detailed information, double-click a resource in Resource\nManager. If you have multiple versions of a resource, this detailed view\ndisplays each version along with any associated qualifiers, as shown in\nfigure 2. From here, you can double-click a specific version to open it\nin an editor window.\n\n**Figure 2.** The Resource Manager showing versions of an image resource for\ndifferent screen densities.\n\nImport drawables into your project\n----------------------------------\n\nYou can use the Resource Manager to import image resources into your project.\nFor a list of supported image types, see\n[Image support](/guide/topics/media/media-formats#image-formats).\n\nTo import image resources into your project, do the following:\n\n1. Drag your images directly onto the **Resource Manager** window in\n Android Studio.\n\n - Alternatively, you can:\n 1. Click the plus icon (**+**).\n 2. Choose **Import Drawables**, as shown in figure 3.\n 3. Select the files and folders that you want to import.\n\n **Figure 3.** Select **Import Drawables** from the menu.\n2. The **Import drawables** dialog appears, as shown in figure 4. This dialog\n displays a list of the resources you're importing. You can rename resources\n by clicking the text box above a resource's preview.\n\n If you're providing multiple versions of the same resource, add\n [device configuration qualifiers](#automatic-parsing), as described in the\n following section, that describe the\n specific configuration that each resource supports.\n\n For example, if you're providing multiple versions of the same resource for\n different screen densities, you can add a **Density** qualifier for each\n version. Note that if two or more resources have the same name and\n qualifiers, only one version is imported.\n\n For more information on resource qualifiers, see\n [Providing alternative resources](/guide/topics/resources/providing-resources#AlternativeResources).\n\n **Figure 4.** The **Import drawables** dialog.\n\n Once you've named your resources and added any necessary qualifiers, click\n **Next**.\n3. The next screen shows a summary of the resources you're importing. When\n you're ready to import, click **Import**.\n\nIn the **Resource Manager** window, your resources are now ready for you to use\nin your project, as shown in figure 5.\n\n**Figure 5.** The Resource Manager now shows your imported images.\n\n### Automatically parse drawable densities\n\nWhen you import a file or folder and its path contains a density qualifier,\nthe Resource Manager automatically applies the density qualifier as part of the\nimport. The Resource Manager can parse both Android's density qualifiers and\niOS's scale factors.\n\nThis table lists how different supported densities are represented for\nAndroid and iOS:\n\n| Density | Android density qualifier | iOS scaling factor |\n|--------------------------------------------|---------------------------|--------------------|\n| Low-density (\\~120 dpi) | `ldpi` | not supported |\n| Medium-density (\\~160 dpi) | `mdpi` | original scale |\n| High-density (\\~240 dpi) | `hdpi` | not supported |\n| Extra-high-density (\\~320 dpi) | `xhdpi` | @2x |\n| Extra-extra-high-density (\\~480 dpi) | `xxhdpi` | @3x |\n| Extra-extra-extra-high-density (\\~640 dpi) | `xxxhdpi` | @4x |\n\nHere are some examples of how input paths translate to resource paths after\nimport:\n\nAndroid density qualifier: `hdpi`\n: **Input path:** /UserFolder/icon1/***hdpi*** /icon.png \n\n **Resource path:** *\\\u003cprojectFolder\\\u003e* /*\\\u003cmoduleFolder\\\u003e* /src/main/res/***drawable-hdpi***/icon.png\n\nAndroid density qualifier: `xxhdpi`\n: **Input path:** /UserFolder/icon1/abc-***xxhdpi*** /icon.png \n\n **Resource path:** *\\\u003cprojectFolder\\\u003e* /*\\\u003cmoduleFolder\\\u003e* /src/main/res/***drawable-xxhdpi***/icon.png\n\niOS scaling factor: @2x\n: **Input path:** /UserFolder/icon1/icon***@2x*** .png \n\n **Resource path:** *\\\u003cprojectFolder\\\u003e* /*\\\u003cmoduleFolder\\\u003e* /src/main/res/***drawable-xhdpi***/icon.png\n\niOS scaling factor: @2x\n: **Input path:** /UserFolder/icon1/icon***@2x*** _alternate.png \n\n **Resource path:** *\\\u003cprojectFolder\\\u003e* /*\\\u003cmoduleFolder\\\u003e* /src/main/res/***drawable-xhdpi***/icon_alternate.png\n\nFor more information on supporting devices with different pixel densities, see\n[Support different pixel densities](/training/multiscreen/screendensities).\n\nDrag drawables into your layout\n-------------------------------\n\nYou can drag drawables from the Resource Manager directly onto a\nlayout. When you drag a resource onto a layout, the Resource Manager creates a\ncorresponding `ImageView` for that drawable, as shown in animation 1:\n\n**Animation 1.** Drag drawables onto a layout in **Design**\nview.\n\nYou can also drag directly onto the XML of the layout, as shown in\nanimation 2:\n\n**Animation 2.** Drag drawables onto a layout in **Text** view.\n\nWhen dragging a drawable onto a layout in the **Text** tab, the generated code\ndiffers depending on where you place the drawable in the layout:\n\n- If you drag a drawable onto a blank area, the Resource Manager generates a corresponding `ImageView`.\n- If you drag a drawable onto any attribute in the layout XML, the Resource Manager replaces that attribute value with a reference to the drawable. You can also drag any other resource type onto an XML attribute to replace the attribute value.\n- If you drag a drawable onto an existing `ImageView` element, the Resource Manager replaces the corresponding source attribute."]]