Menu & Toolbar
Menu និង Toolbar
Menu និង Toolbar គឺជាផ្នែកសំខាន់នៃ Android UI ដែលផ្តល់នូវ navigation និង actions សម្រាប់អ្នកប្រើប្រាស់។
📱 ប្រភេទ Menu
Menu Type | ពិពណ៌នា | ពេលណាប្រើ |
---|---|---|
Options Menu | Menu នៅ Toolbar/ActionBar | Global actions (Settings, Search, Share) |
Context Menu | Long press លើ item | Item-specific actions (Delete, Edit) |
Popup Menu | Menu popup modal | Additional actions overflow |
🎨 Toolbar (ActionBar)
Toolbar គឺជា ActionBar version ទំនើប និង flexible ជាង។
1️⃣ បន្ថែម Toolbar ក្នុង Layout
Java Code
2️⃣ Setup Toolbar ក្នុង Activity
Java Code
📋 Options Menu
1️⃣ បង្កើត Menu Resource File
បង្កើត folder res/menu/
និង file menu_main.xml
:
Java Code
2️⃣ Inflate Menu ក្នុង Activity
Java Code
🎯 Menu Icons
Android ផ្តល់ built-in icons សម្រាប់ actions ធម្មតា:
Icon | Resource |
---|---|
⚙️ Settings | @android:drawable/ic_menu_preferences |
🔍 Search | @android:drawable/ic_menu_search |
📤 Share | @android:drawable/ic_menu_share |
➕ Add | @android:drawable/ic_menu_add |
📲 Context Menu
Java Code
🎪 Popup Menu
Java Code
🎨 Customize Toolbar
អ្នកអាច customize Toolbar color, title, subtitle:
Java Code
✨ Material Design: ប្រើ Material Design icons សម្រាប់ UI ទំនើប! Download ពី Material Icons
✅ Best Practices
- ដាក់ common actions នៅលើ Toolbar (Settings, Search)
- ប្រើ icons ច្បាស់លាស់ និងស្គាល់ងាយ
- មិនត្រូវដាក់ actions ច្រើនពេក (max 3-4)
- ប្រើ overflow menu សម្រាប់ secondary actions
- Enable back button នៅពេលចាំបាច់