編輯:關於 Android 程式設計
本教程會實作一個具有 Material Design 風格的 Android 畫面,包含 DrawerLayout、FloatingActionButton、Snackbar、Toolbar、TabLayout、CollapsingToolbarLayout 與 NavigationView。


在 Android Studio 中,可透過 Open Module Settings 加入 Library dependency。Eclipse 則需要導入 support 與 design 相關專案,並將 design 設為 Library。
FloatingActionButton 是 Material Design 中常見的圓形浮動按鈕。為了讓它在畫面右下角對齊,可用 FrameLayout 或 CoordinatorLayout 包裹。

Snackbar 會在畫面底部顯示簡短訊息。它與 Toast 概念類似,但更像是 UI 的一部分。

點擊 FAB 後,可呼叫 Snackbar 顯示提示。

CoordinatorLayout 可讓子 View 彼此協調。把 FrameLayout 改為 CoordinatorLayout 後,FAB 會依 Snackbar 出現與消失而移動。


Toolbar 可取代傳統 ActionBar,彈性更高。可先隱藏 ActionBar,再把 Toolbar 設為 Support ActionBar。

若內容需要捲動並與 AppBar 協調,可加上 app:layout_behavior。


TabLayout 可用來建立分頁標籤。它可放在 AppBarLayout 中,與 Toolbar 一起呈現。


若希望 AppBar 隨內容捲動離開畫面,可設定捲動標記。但 ScrollView 不適合直接與 CoordinatorLayout 協作,建議改用 NestedScrollView 或 RecyclerView。




CollapsingToolbarLayout 可讓 Toolbar 具備收縮與展開效果。若要固定 Toolbar 圖示,可為 Toolbar 加上 pin 模式。


使用 CollapsingToolbarLayout 後,標題可能需要透過 setTitle 設定。


CollapsingToolbarLayout 繼承自 FrameLayout,可加入 ImageView 作為背景。若要讓背景圖隨捲動產生視差,可設定 parallax 模式。




NavigationView 可用來實作 Drawer Menu。只要建立 header 版面與 menu 資源,再綁定到 NavigationView,即可快速完成側邊選單。

TextInputLayout 可讓 EditText 具備浮動提示與錯誤訊息顯示,是 Material Design 中常見的輸入欄位元件。
用 Android MenuInflater 建立選單項的步驟教學
建立選單項若全靠 menu.add() 逐一手動新增,不僅效率低落、維護不易。Android 提供了更優雅的方式——MenuInflater,透過 XML 佈局檔來定義選
Android SQLite 資料庫完整實例教學
Android 作為目前主流的行動作業系統,與 SQLite 佔用資源少的優勢十分契合,因此平台內建了一個嵌入式關聯式資料庫——SQLite。若需要在 Android 上
Android 常用資料儲存方式:SharedPreferences、檔案與 SQLite
Android 應用常需要保存資料,例如使用者設定、登入狀態、離線內容或結構化記錄。常見的資料儲存方式包含 SharedPreferences、檔案儲存與 SQLite。
Android 登入頁面的實作要點
登入頁面是許多 App 的入口,雖然結構看似簡單,但細節會直接影響使用者體驗。本文以常見表單為例,說明輸入框、清除鈕與密碼顯示切換的實作重點。 版面配置 登入表單通常包