Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲

Android icon 與 logo 的差別:配置屬性與 ActionBar 應用

編輯:關於 Android 程式設計

AndroidManifest 裡同時有 android:icon 和 android:logo 兩個屬性,很多人從沒想過它們有何不同,於是也從沒正確用過。搞懂這兩者的分工,ActionBar 的視覺呈現會專業很多。

一、activity 的 icon 屬性

官方說明大意如下:

An icon representing the activity. The icon is displayed to users when a representation of the activity is required on-screen. For example, icons for activities that initiate tasks are displayed in the launcher window. The icon is often accompanied by a label.

This attribute must be set as a reference to a drawable resource. If it is not set, the icon specified for the application as a whole is used instead.

The activity's icon — whether set here or by the application element — is also the default icon for all the activity's intent filters.

翻譯成白話:icon 代表「這個 Activity」,凡是系統需要一個圖形來指代它時就顯示這張圖,最典型的就是啟動器上的桌面圖標,通常還會搭配一個文字標籤。屬性值必須是 drawable 資源。若 Activity 沒設定,就沿用 application 的 icon。

二、application 的 icon 屬性

An icon for the application as whole, and the default icon for each of the application's components. This attribute must be set as a reference to a drawable resource. There is no default icon.

與 Activity 的類似,但有兩個關鍵差異:application 的 icon 沒有預設值;而且它主要用在安裝介面與安裝包縮圖,並不包括桌面與啟動器圖標。桌面上顯示的,是主 Activity(一般叫 MainActivity)的 icon。

實務上的建議是:application 的 icon 用較精緻、細節豐富的方形圖(安裝器裡通常尺寸較大);MainActivity 的 icon 則要符合啟動器圖標的視覺規範。

三、logo 屬性

A logo for the application as whole, and the default logo for activities. This attribute must be set as a reference to a drawable resource. There is no default logo.

logo 不會被當作桌面圖標,它只用於 Activity 的導航列(ActionBar)。而如果同時設定了 icon 與 logo,ActionBar 會完全用 logo 覆蓋 icon。

四、官方建議:用 logo 取代 icon 的做法

By default, the system uses your application icon in the action bar. However, if you also specify the logo attribute, then the action bar uses the logo image instead of the icon.

A logo should usually be wider than the icon, but should not include unnecessary text. You should generally use a logo only when it represents your brand in a traditional format that users recognize. A good example is the YouTube app's logo — the logo represents the expected user brand, whereas the app's icon is a modified version that conforms to the square requirement for the launcher icon.

重點整理:

  • logo 通常比 icon 寬(因為 ActionBar 是橫向空間),但不要塞入多餘文字。
  • 只在 logo 能代表使用者熟悉的品牌形象時才使用。
  • YouTube 是最好的例子:ActionBar 用 logo 呈現品牌,桌面圖標則是符合方形規範的變體版本。

五、ActionBar 的實際控制

ActionBar actionBar = getActionBar();

隱藏文字標籤

actionBar.setDisplayShowTitleEnabled(false);

隱藏 logo 與 icon

actionBar.setDisplayShowHomeEnabled(false);

切換為 overlay 模式

預設情況下,ActionBar 佔據 Activity 頂部並參與布局計算。設為 overlay 模式後,ActionBar 相當於浮在內容之上,不干涉 Activity 的布局,適合實作沉浸式的大圖首頁:

// 在 styles.xml 或 themes.xml 中
<item name="android:windowActionBarOverlay">true</item>

// 或在 Java 中
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);

六、對照表

  • application:icon → 安裝介面、安裝包縮圖。無預設值。
  • activity:icon → 桌面/啟動器圖標、intent filter 的預設圖。未設定時沿用 application 的值。
  • android:logo → ActionBar 導航列。設定了就會覆蓋 icon。不影響桌面圖標。

換句話說,icon 是「給系統和系統 UI 看的」,logo 是「給 App 內部介面看的」。兩者用途不重疊,最保險的做法是兩個都設,各自用合適的素材。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © Android教程網 All Rights Reserved