RelativeLayout 中 Button 預設背景含透明度(Material Design 狀態列表動畫),導致底下 ImageView 透出。解決方法:為 Button 設定不透明背景色或自訂 Selector。
| 方案 | 透明度 | 按壓回饋 | 維護性 | 建議場景 |
|---|---|---|---|---|
| android:background="#RRGGBB" | 完全不透明 | 無 | 極簡 | 靜態按鈕、原型開發 |
| 自訂 Selector | 完全不透明 | 有 | 中 | 需狀態視覺回饋 |
| MaterialButton | 完全不透明 | 有 (Ripple) | 高 | 新專案、Material Design 規範 |
AppCompat Button (AppCompatButton) 預設背景為 btn_default_material,包含狀態列表:
state_pressed:Ripple 效果(半透明)state_focused:淡色覆蓋default:主題色 + 透明度設定 android:background 會完全取代此預設 Selector,故需自行提供不透明版本。
MaterialButton,獲得一致的 Material 風格與不透明背景。
2. 舊專案統一建立 button_primary, button_secondary 等 Selector 資源,集中管理。
3. 避免在 XML 中混用 android:background 與 style 設定背景,優先順序不一致易導致混淆。
為 Button 明確設定不透明背景,即可解決覆蓋 ImageView 時透出底圖問題。