定義自訂動畫
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
這個網頁已淘汰。如需舊版說明文件,請參閱下文。
自訂輕觸回饋
Material Design 中的觸控意見回饋功能可在使用者與 UI 元素互動時,在接觸點立即進行視覺確認。按鈕的預設觸控回饋動畫使用新的 RippleDrawable
類別,該類別會以漣漪效果轉換不同的狀態。
在多數情況下,您應指定檢視畫面背景,在檢視區塊 XML 中套用此功能:
?android:attr/selectableItemBackground
代表受限漣漪。
?android:attr/selectableItemBackgroundBorderless
適用於延伸至該檢視畫面的漣漪效果。它會由最靠近檢視畫面的父項 (使用非空值背景) 繪製和邊界。
注意: selectableItemBackgroundBorderless
是在 API 級別 21 中導入的新屬性。
或者,您也可以使用 ripple
元素將 RippleDrawable
定義為 XML 資源。
您可以將顏色指派給 RippleDrawable
物件。如要變更預設的觸控回饋顏色,請使用主題的 android:colorControlHighlight
屬性。
詳情請參閱 RippleDrawable
類別的 API 參考資料。
使用揭露效果
請參閱「建立圓形動畫動畫」。
自訂操作行為轉換
請參閱「以動畫開始活動」。
使用曲線動態效果
請參閱「使用曲線動態效果」。
以動畫呈現檢視畫面狀態變更
請參閱「使用 StateListAnimator 為檢視畫面狀態變更加上動畫效果」。
以動畫方式呈現向量可繪項目
請參閱「動畫動畫可繪項目圖形」。
這個頁面中的內容和程式碼範例均受《內容授權》中的授權所規範。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,["# Defining Custom Animations\n\n**This page is deprecated.** See below for the new location for\ndocumentation that used to be here.\n\nCustomize Touch Feedback\n------------------------\n\nTouch feedback in material design provides an instantaneous visual confirmation at the\npoint of contact when users interact with UI elements. The default touch feedback animations\nfor buttons use the new [RippleDrawable](/reference/android/graphics/drawable/RippleDrawable) class, which transitions\nbetween different states with a ripple effect.\n\nIn most cases, you should apply this functionality in your view XML by specifying the view\nbackground as:\n\n- `?android:attr/selectableItemBackground` for a bounded ripple.\n- `?android:attr/selectableItemBackgroundBorderless` for a ripple that extends beyond the view. It will be drawn upon, and bounded by, the nearest parent of the view with a non-null background.\n\n**Note:** `selectableItemBackgroundBorderless` is a new\nattribute introduced in API level 21.\n\nAlternatively, you can define a [RippleDrawable](/reference/android/graphics/drawable/RippleDrawable)\nas an XML resource using the `ripple` element.\n\nYou can assign a color to [RippleDrawable](/reference/android/graphics/drawable/RippleDrawable) objects. To change\nthe default touch feedback color, use the theme's `android:colorControlHighlight`\nattribute.\n\nFor more information, see the API reference for the [RippleDrawable](/reference/android/graphics/drawable/RippleDrawable) class.\n\nUse the Reveal Effect\n---------------------\n\nSee [Create a circular reveal animation](/training/animation/reveal-or-hide-view#Reveal).\n\n\nCustomize Activity Transitions\n------------------------------\n\nSee [Start an Activity with an Animation](/training/transitions/start-activity).\n\nUse Curved Motion\n-----------------\n\nSee [Use curved motion](/training/animation/reposition-view#CurvedMotion).\n\nAnimate View State Changes\n--------------------------\n\nSee [Using StateListAnimator to\nanimate view state changes](/guide/topics/graphics/prop-animation#ViewState).\n\nAnimate Vector Drawables\n------------------------\n\nSee [Animate Drawable Graphics](/guide/topics/graphics/drawable-animation)."]]