編輯:關於 Android 程式設計
從 Android 5.0 開始,Google 官方為我們準備了不少既美觀又便利的轉場動畫。
原生提供的普通轉場動畫包括:
- fade 漸隱漸現
- slide 各元素先後滑動進入
- Explode 分裂成兩部分再進入
分享元素的轉場動畫則有:
- changeBound 最為常用,用來改變 View 的大小與位置
- changeClipBounds 改變 Clip 邊界的大小
- changeImageTransform 改變 ImageView 的大小與 matrix
- ChangeTransform 改變普通 View 的一些 scaleX 值
- ChangeScroll 改變滑動位置
這些都是原生的能力。然而面對一些複雜的轉場動畫,Google 提供的這幾個仍嫌不足,很多時候都得自己定義轉場動畫。例如下面這個轉場,用原生動畫就很難實現:

顶部 title bar 與底部輸入框的進入、返回動畫;第一個頁面的評論圓球透過揭露效果,顯示到第二頁面的內容詳情頁。
一開始我想用官方元素的 slide 或 Explode 來實現,但基本都行不通,最後只能自己動手寫一個轉場動畫。其實轉場動畫並不難,只要繼承 Visibility 或 Transition 即可(其中 Visibility 是繼承自 Transition 的)。
如果轉場動畫只是某個 View 出現或消失,可以考慮繼承 Visibility;若是類似 ShareElem 那樣的轉場動畫,就得繼承 Transition。
回到重點,我們要實現的第一個問題是:
頂部 title bar 與底部輸入框的進入、返回動畫
繼承 Visibility 有四個方法需要重寫:
1. public void captureStartValues(TransitionValues transitionValues)——在這裡保存計算動畫初始狀態所需的屬性值
2. public void captureEndValues(TransitionValues transitionValues)——在這裡保存計算動畫結束狀態所需的屬性值
3. public Animator onAppear(ViewGroup sceneRoot, final View view, TransitionValues startValues, TransitionValues endValues)——若是進入動畫(即顯示某個 View)便會執行這個方法
4. public Animator onDisappear(ViewGroup sceneRoot, final View view, TransitionValues startValues, TransitionValues endValues)——若是退出(即不再顯示某個 View)便會執行這個方法
可以發現,頂部 title bar 與底部輸入框的動畫其實非常單純,僅有 TranslationY 這一個位移。我們只需在 captureStartValues、captureEndValues 中分別計算並保存開始與結束位置所需的位移,然後在 onAppear 與 onDisappear 中建立動畫即可。
具體請參考程式碼:
public class CommentEnterTransition extends Visibility { private static final String TAG = "CommentEnterTransition"; private static final String PROPNAME_BOTTOM_BOX_TRANSITION_Y = "custom_bottom_box_enter_transition:change_transY:transitionY"; private static final String PROPNAME_TOP_BAR_TRANSITION_Y = "custom_top_bar_transition:change_transY:transitionY"; private View mBottomView; private View mTopBarView; private Context mContext; public CommentEnterTransition(Context context, View topBarView, View bottomView) { mBottomView = bottomView; mTopBarView = topBarView; mContext = context; } @Override public void captureStartValues(TransitionValues transitionValues) { super.captureStartValues(transitionValues); mBottomView.measure(0, 0); int transY = mBottomView.getMeasuredHeight(); // 保存 計算初始值 transitionValues.values.put(PROPNAME_BOTTOM_BOX_TRANSITION_Y, transY); transitionValues.values.put(PROPNAME_TOP_BAR_TRANSITION_Y, -mContext.getResources().getDimensionPixelOffset(R.dimen.top_bar_height)); } @Override public void captureEndValues(TransitionValues transitionValues) { super.captureEndValues(transitionValues); // 保存計算結束值 transitionValues.values.put(PROPNAME_BOTTOM_BOX_TRANSITION_Y, 0); transitionValues.values.put(PROPNAME_TOP_BAR_TRANSITION_Y, 0); } @Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { return super.createAnimator(sceneRoot, startValues, endValues); } @Override public Animator onAppear(ViewGroup sceneRoot, final View view, TransitionValues startValues, TransitionValues endValues) { if (null == startValues || null == endValues) { return null; } // 這裡去除 之前 存儲的 初始值 和 結束值, 然後執行東湖 if (view == mBottomView) { int startTransY = (int) startValues.values.get(PROPNAME_BOTTOM_BOX_TRANSITION_Y); int endTransY = (int) endValues.values.get(PROPNAME_BOTTOM_BOX_TRANSITION_Y); if (startTransY != endTransY) { ValueAnimator animator = ValueAnimator.ofInt(startTransY, endTransY); // 注意這裡不能使用 屬性動畫, 使用 ValueAnimator 然後在更新 View 的對應屬性 animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Object value = animation.getAnimatedValue(); if (null != value) { view.setTranslationY((Integer) value); } } }); return animator; } } else if (view == mTopBarView) { int startTransY = (int) startValues.values.get(PROPNAME_TOP_BAR_TRANSITION_Y); int endTransY = (int) endValues.values.get(PROPNAME_TOP_BAR_TRANSITION_Y); if (startTransY != endTransY) { ValueAnimator animator = ValueAnimator.ofInt(startTransY, endTransY); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Object value = animation.getAnimatedValue(); if (null != value) { view.setTranslationY((Integer) value); } } }); return animator; } } return null; } @Override public Animator onDisappear(ViewGroup sceneRoot, final View view, TransitionValues startValues, TransitionValues endValues) { if (null == startValues || null == endValues) { return null; } // 這裡執行 返回動畫, 這裡金 初始值 和技術值 對調了,這樣動畫, 就就和原來動畫想反了 if (view == mBottomView) { int startTransY = (int) endValues.values.get(PROPNAME_BOTTOM_BOX_TRANSITION_Y); int endTransY = (int) startValues.values.get(PROPNAME_BOTTOM_BOX_TRANSITION_Y); if (startTransY != endTransY) { ValueAnimator animator = ValueAnimator.ofInt(startTransY, endTransY); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Object value = animation.getAnimatedValue(); if (null != value) { view.setTranslationY((Integer) value); } } }); return animator; } } else if (view == mTopBarView) { int startTransY = (int) endValues.values.get(PROPNAME_TOP_BAR_TRANSITION_Y); int endTransY = (int) startValues.values.get(PROPNAME_TOP_BAR_TRANSITION_Y); if (startTransY != endTransY) { ValueAnimator animator = ValueAnimator.ofInt(startTransY, endTransY); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Object value = animation.getAnimatedValue(); if (null != value) { view.setTranslationY((Integer) value); } } }); return animator; } } return null; } }
最後把自訂的轉場動畫掛上去即可:
getWindow().setEnterTransition(new CommentEnterTransition(this, mTitleBarTxt, mBottomSendBar));
再看看效果:

首先可以確定這是一個分享元素的轉場動畫。一開始我想用原生的 ChangeBounds 簡單實現,但問題是從圓形變成矩形的過程太過生硬,最後只能自己動手寫轉場動畫。
我們再來分析上面那個轉場動畫:
1. 揭露效果:從第一個頁面的圓球開始,圓球慢慢放大,直到整個動畫結束;
2. 看似 View 在動畫過程中慢慢放大;
3. 似乎還帶有曲線位移的動畫?
其實只要你真的自己寫過轉場動畫,就能排除第二點——分享元素的轉場動畫一開始 view 就已經變成第二個頁面中的 View 了,所以並不存在放大過程。
好,我們先解決第一個問題:揭露動畫。這是 Android 5.0 之後原生提供的能力,用起來特別簡單:
ViewAnimationUtils.createCircularReveal(view, centerX, centerY,startRadius, endRadius);
其中 centerX、centerY 是揭露圓心的位置;startRadius、endRadius 則是開始時與結束時圓形的半徑。
接下來,我們需要繼承 Transition 來實作揭露動畫。繼承 Transition 需重寫以下三個方法:
1. public void captureStartValues(TransitionValues transitionValues)——能取得上一個頁面對應 View 的一些屬性值
2. public void captureEndValues(TransitionValues transitionValues)——能取得即將打開的頁面對應 View 的一些屬性值
3. public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues)——在這裡建立對應的轉場動畫
好,那麼為了實現上面的揭露動畫,我們一開始需要取得的值有:
1. 上一個頁面圓形 View 的寬度,作為揭露圓形最初的半徑;
2. 即將打開頁面的對應 View 的對角線長度,作為揭露圓形的最終半徑;
3. 揭露動畫的圓心位置,這裡我們取 View 的中間位置。
這樣就能實作一個簡單的轉場揭露動畫了。先看程式碼,再看效果。
public class ShareElemEnterRevealTransition extends Transition { private static final String TAG = "ShareElemEnterRevealTransition"; private static final String PROPNAME_RADIUS = "custom_reveal:change_radius:radius"; private boolean hasAnim = false; private View animView; public ShareElemEnterRevealTransition(View animView) { this.animView = animView; } @Override public void captureStartValues(TransitionValues transitionValues) { transitionValues.values.put(PROPNAME_RADIUS, transitionValues.view.getWidth() / 2); } @Override public void captureEndValues(TransitionValues transitionValues) { View view = transitionValues.view; float widthSquared = view.getWidth() * view.getWidth(); float heightSquared = view.getHeight() * view.getHeight(); int radius = (int) Math.sqrt(widthSquared + heightSquared) / 2; transitionValues.values.put(PROPNAME_RADIUS, radius); } @Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { if (null == startValues || null == endValues) { return null; } final View view = endValues.view; int startRadius = (int) startValues.values.get(PROPNAME_RADIUS); int endRadius = (int) endValues.values.get(PROPNAME_RADIUS); if (view == animView) { Animator reveal = createAnimator(view, startRadius, endRadius); hasAnim = true; return reveal; } return null; } private Animator createAnimator(View view, float startRadius, float endRadius) { int centerX = view.getWidth() / 2; int centerY = view.getHeight() / 2; Animator reveal = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, endRadius); return new NoPauseAnimator(reveal); } }
效果:

貌似差距有點大——沒有顏色的漸變,而且揭露圓形似乎固定在第二頁面 View 的圓心,缺乏移動感。好,接下來要處理的有:
1. 移動 View;
2. 背景顏色漸變。
透過上面的程式碼範例,做這兩件事應該不難,下面直接上程式碼(背景顏色漸變):
public class ChangeColor extends Transition { private static final String TAG = "ChangeColor"; private static final String PROPNAME_BACKGROUND = "customtransition:change_color:backgroundcolor"; int mStartColor; int mEndColor; public ChangeColor(int startColor, int endColor) { this.mStartColor = startColor; this.mEndColor = endColor; } private void captureValues(TransitionValues values) { values.values.put(PROPNAME_BACKGROUND, values.view.getBackground()); } @Override public void captureStartValues(TransitionValues transitionValues) { captureValues(transitionValues); transitionValues.values.put(PROPNAME_BACKGROUND, mStartColor); } @Override public void captureEndValues(TransitionValues transitionValues) { transitionValues.values.put(PROPNAME_BACKGROUND, mEndColor); } @Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { if (null == startValues || null == endValues) { return null; } final View view = endValues.view; int startColor = (int) startValues.values.get(PROPNAME_BACKGROUND); int endColor = (int) endValues.values.get(PROPNAME_BACKGROUND); if (startColor != endColor) { ValueAnimator animator = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { Object value = animation.getAnimatedValue(); if (null != value) { view.setBackgroundColor((Integer) value); } } }); return animator; } return null; } }
改變位置(曲線運動):
public class ChangePosition extends Transition { private static final String TAG = "ChangePosition"; private static final String PROPNAME_POSITION = "custom_position:change_position:position"; public ChangePosition() { // 這裡通過曲線的方式 來改變位置 setPathMotion(new PathMotion() { @Override public Path getPath(float startX, float startY, float endX, float endY) { Path path = new Path(); path.moveTo(startX, startY); float controlPointX = (startX + endX) / 3; float controlPointY = (startY + endY) / 2; // 這裡是一條貝塞爾曲線的路基, (controlPointX, controlPointY) 表示控制點 path.quadTo(controlPointX, controlPointY, endX, endY); return path; } }); } private void captureValues(TransitionValues values) { values.values.put(PROPNAME_POSITION, values.view.getBackground()); Rect rect = new Rect(); values.view.getGlobalVisibleRect(rect); values.values.put(PROPNAME_POSITION, rect); } @Override public void captureStartValues(TransitionValues transitionValues) { captureValues(transitionValues); } @Override public void captureEndValues(TransitionValues transitionValues) { captureValues(transitionValues); } @Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { if (null == startValues || null == endValues) { return null; } if (startValues.view.getId() > 0) { Rect startRect = (Rect) startValues.values.get(PROPNAME_POSITION); Rect endRect = (Rect) endValues.values.get(PROPNAME_POSITION); final View view = endValues.view; Path changePosPath = getPathMotion().getPath(startRect.centerX(), startRect.centerY(), endRect.centerX(), endRect.centerY()); int radius = startRect.centerY() - endRect.centerY(); ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, new PropPosition(PointF.class, "position", new PointF(endRect.centerX(), endRect.centerY())), null, changePosPath); objectAnimator.setInterpolator(new FastOutSlowInInterpolator()); return objectAnimator; } return null; } static class PropPosition extends Property { public PropPosition(Class type, String name) { super(type, name); } public PropPosition(Class type, String name, PointF startPos) { super(type, name); this.startPos = startPos; } PointF startPos; @Override public void set(View view, PointF topLeft) { int x = Math.round(topLeft.x); int y = Math.round(topLeft.y); int startX = Math.round(startPos.x); int startY = Math.round(startPos.y); int transY = y - startY; int transX = x - startX; // 這裡控制 View 移動 view.setTranslationX(transX); view.setTranslationY(transY); } @Override public PointF get(View object) { return null; } } }
上面改變位置時採用了 Path 動畫,讓 View 能以貝茲曲線的方式位移。
好,enter 的動畫基本處理完了,但返回時仍有點問題。看圖:

返回時,View 的大小已經變成了後面那個頁面 View 的大小,由於尺寸受限,揭露動畫幾乎看不出效果。所以分享元素的返回動畫也需要做一些細微調整。
關於改變 View 大小的問題,我研究了 ChangeBounds 的原始碼,發現它是透過呼叫 View 一個隱藏方法來實現的:
/** * Same as setFrame, but public and hidden. For use in {@link android.transition.ChangeBounds}. * @hide */ public void setLeftTopRightBottom(int left, int top, int right, int bottom) { setFrame(left, top, right, bottom); }
後來發現有適配問題:這個方法只在 5.1 或以上才有,5.0 上並沒有。於是又看了 5.0 的 ChangeBounds 原始碼,發現 5.0 上改變 View 大小是透過以下方式實現的:
view.setLeft(left); view.setRight(right); view.setTop(top); view.setBottom(bottom);
其實 5.0 的這組 set 方法在 5.1 或以上也同樣可用。所以改變 View 大小,可以選擇在 5.1 以上用反射呼叫 setLeftTopRightBottom,也可以直接統一使用 set 方法。
下面附上返回動畫的部分程式碼。改變位置:
public class ShareElemReturnChangePosition extends Transition { private static final String TAG = "ShareElemReturnChangePosition"; private static final String PROPNAME_POSITION = "custom_position:change_position:position"; public ShareElemReturnChangePosition() { setPathMotion(new PathMotion() { @Override public Path getPath(float startX, float startY, float endX, float endY) { Path path = new Path(); path.moveTo(startX, startY); float controlPointX = (startX + endX) / 3; float controlPointY = (startY + endY) / 2; path.quadTo(controlPointX, controlPointY, endX, endY); return path; } }); } private void captureValues(TransitionValues values) { values.values.put(PROPNAME_POSITION, values.view.getBackground()); Rect rect = new Rect(); values.view.getGlobalVisibleRect(rect); values.values.put(PROPNAME_POSITION, rect); } @Override public void captureStartValues(TransitionValues transitionValues) { captureValues(transitionValues); } @Override public void captureEndValues(TransitionValues transitionValues) { captureValues(transitionValues); } @Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) { if (null == startValues || null == endValues) { return null; } if (startValues.view.getId() > 0) { Rect startRect = (Rect) startValues.values.get(PROPNAME_POSITION); Rect endRect = (Rect) endValues.values.get(PROPNAME_POSITION); final View view = endValues.view; Rect rect = new Rect(); view.getGlobalVisibleRect(rect); Path changePosPath = getPathMotion().getPath(startRect.centerX(), startRect.centerY(), endRect.centerX(), endRect.centerY() - endRect.height() / 2); ObjectAnimator objectAnimator = ObjectAnimator.ofObject(view, new PropPosition(PointF.class, "position", new PointF(startRect.centerX(), startRect.centerY())), null, changePosPath); objectAnimator.setInterpolator(new FastOutSlowInInterpolator()); return objectAnimator; } return null; } static class PropPosition extends Property { public PropPosition(Class type, String name) { super(type, name); } public PropPosition(Class type, String name, PointF startPos) { super(type, name); this.startPos = startPos; } PointF startPos; @Override public void set(View view, PointF topLeft) { int x = Math.round(topLeft.x); int y = Math.round(topLeft.y); int startX = Math.round(startPos.x); int startY = Math.round(startPos.y); int transY = y - startY; int transX = x - startX; Rect rect = new Rect(); view.getGlobalVisibleRect(rect); view.setTranslationX(transX); view.setTranslationY(transY); } @Override public PointF get(View object) { return null; } } }
揭露動畫:
public class ShareElemReturnRevealTransition extends Transition { private static final String TAG = "ShareElemReturnRevealTransition"; private static final String PROPNAME_BACKGROUND = "custom_reveal:change_radius:radius"; private boolean hasAnim = false; private View animView; private Rect startRect; private Rect endRect; public ShareElemReturnRevealTransition(View animView) { this.animView = animView; startRect = new Rect(); endRect = new Rect(); } @Override public void captureStartValues(TransitionValues transitionValues) { View view = transitionValues.view; float widthSquared = view.getWidth() * view.getWidth(); float heightSquared = view.getHeight() * view.getHeight(); int radius = (int) Math.sqrt(widthSquared + heightSquared) / 2; transitionValues.values.put(PROPNAME_BACKGROUND, radius); transitionValues.view.getGlobalVisibleRect(startRect); } @Override public void captureEndValues(TransitionValues transitionValues) { transitionValues.view.getLocalVisibleRect(endRect); transitionValues.values.put(PROPNAME_BACKGROUND, transitionValues.view.getWidth() / 2); } @Override public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, final TransitionValues endValues) { if (null == startValues || null == endValues) { return null; } final View view = endValues.view; int startRadius = (int) startValues.values.get(PROPNAME_BACKGROUND); int endRadius = (int) endValues.values.get(PROPNAME_BACKGROUND); // 在執行返回動畫的時候, View 默認的被控制 為 前一個頁面的 ShareElem 的打消了 // 所以這裡 需要改變的 View 大小 才能 正常的使用揭露動畫 // 反射調用 relfectInvoke(view, startRect.left, startRect.top, startRect.right, startRect.bottom ); Animator reveal = createAnimator(view, startRadius, endRadius); // 在動畫的最後 被我們放大後的 View 會閃一些 這裡可以有防止那種情況發生 reveal.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); view.setClipBounds(new Rect(0, 0, 1, 1)); view.setVisibility(View.GONE); } }); return reveal; } private Animator createAnimator(View view, float startRadius, float endRadius) { int centerX = view.getWidth() / 2; int centerY = view.getHeight() / 2; Animator reveal = ViewAnimationUtils.createCircularReveal(view, centerX, centerY, startRadius, endRadius); return new ShareElemEnterRevealTransition.NoPauseAnimator(reveal); } // setLeftTopRightBottom 需要反射執行, 該方法能夠控制 View 的大小以及位置 在 ChangeBounds 類中有調用 private void relfectInvoke(View view, int left, int top, int right, int bottom) { Class clazz = view.getClass(); try { Method m1 = clazz.getMethod("setLeftTopRightBottom", new Class[]{int.class, int.class, int.class, int.class}); m1.invoke(view, left, top, right, bottom); } catch (Exception e) { e.printStackTrace(); // 5.0版本 沒有 setLeftTopRightBottom 這個方法 使用一下方法 ,額 其實 5.0 以上也可以用這些方法? view.setLeft(left); view.setRight(right); view.setTop(top); view.setBottom(bottom); } } }
好,下面附上 Activity 中如何使用這些動畫:
public class CommentActivity extends AppCompatActivity { private static final String TAG = "CommentActivity"; View mBottomSendBar; View mTitleBarTxt; View mCommentBox; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_coment); mCommentBox = findViewById(R.id.comment_box); mTitleBarTxt = findViewById(R.id.txt_title_bar); mBottomSendBar = findViewById(R.id.bottom_send_bar); setTransition(); } private void setTransition() { // 頂部 title 和底部輸入框的進入動畫 getWindow().setEnterTransition(new CommentEnterTransition(this, mTitleBarTxt, mBottomSendBar)); getWindow().setSharedElementEnterTransition(buildShareElemEnterSet()); getWindow().setSharedElementReturnTransition(buildShareElemReturnSet()); } /** * 分享 元素 進入動畫 * @return */ private TransitionSet buildShareElemEnterSet() { TransitionSet transitionSet = new TransitionSet(); Transition changePos = new ChangePosition(); changePos.setDuration(300); changePos.addTarget(R.id.comment_box); transitionSet.addTransition(changePos); Transition revealTransition = new ShareElemEnterRevealTransition(mCommentBox); transitionSet.addTransition(revealTransition); revealTransition.addTarget(R.id.comment_box); revealTransition.setInterpolator(new FastOutSlowInInterpolator()); revealTransition.setDuration(300); ChangeColor changeColor = new ChangeColor(getResources().getColor(R.color.black_85_alpha), getResources().getColor(R.color.white)); changeColor.addTarget(R.id.comment_box); changeColor.setDuration(350); transitionSet.addTransition(changeColor); transitionSet.setDuration(900); return transitionSet; } /** * 分享元素返回動畫 * @return */ private TransitionSet buildShareElemReturnSet() { TransitionSet transitionSet = new TransitionSet(); Transition changePos = new ShareElemReturnChangePosition(); changePos.addTarget(R.id.comment_box); transitionSet.addTransition(changePos); ChangeColor changeColor = new ChangeColor(getResources().getColor(R.color.white), getResources().getColor(R.color.black_85_alpha)); changeColor.addTarget(R.id.comment_box); transitionSet.addTransition(changeColor); Transition revealTransition = new ShareElemReturnRevealTransition(mCommentBox); revealTransition.addTarget(R.id.comment_box); transitionSet.addTransition(revealTransition); transitionSet.setDuration(900); return transitionSet; } }
好,關於自訂過場動畫大致就說到這裡。本文沒有細談如何具體使用過場動畫,也沒談 EnterTransition 與 ReturnTransition 之間的關係,以及最基本的過場動畫用法——這些 Android 官網上都有中文文件,就不再贅述了。
Android 三種對話框寫法總結:AlertDialog、Dialog 與 Activity 樣式視窗
專案裡對話框的需求大致分三類:單純的確認提示、需要自訂版面的進度提示、以及需要輸入資料的表單。這三種對應三種不同的實作方式,本篇逐一整理。 一、AlertDialog:
紅米Note4發表了嗎?海報洩漏的雙鏡頭新機線索
小米日前曝光的一張宣傳海報裡,紅米新代言人劉昊然手上拿著一支手機,低頭看不太出全貌,但有一個細節很清楚:背面是雙鏡頭。這支機器不對應任何已發表的型號,於是外界推測它就是尚
華為榮耀V8手機怎麼支付?榮耀V8怎麼刷手機消費
華為榮耀V8支付與刷卡消費 榮耀V8支援NFC與指紋支付,可通過Huawei Pay在支援銀聯閃付的POS機上使用。 使用時,可在支付頁面選擇公交卡或銀行卡,靠近感應區
Android 安全機制解讀:進程、多用戶與文件權限模型
Android 的安全基石並非什麼黑科技,而是沿用了 Linux 的一套成熟機制:進程隔離、多用戶邊界,以及 UID/GID 加 rwx 權限位。理解了這三層,才能看懂後