Android 方法參數的限制

Android枚舉方案

  1. 方法中限制參數範圍
public void setNumber(@IntRange(from = 0, to = 100) int number) {

     }
  1. 方法參數限制參數值
@IntDef({RED, GREEN})
    @Retention(RetentionPolicy.SOURCE)
    public @interface Color{}

    private static final int RED = 1;
    private static final int GREEN = 2;

    public void setColor(@Color int color) {

    }

獲取View的截圖

View viewRoot = getWindow().getDecorView().getRootView();
        viewRoot.setDrawingCacheEnabled(true);
        Bitmap screenShotAsBitmap = Bitmap.createBitmap(viewRoot.getDrawingCache());
        viewRoot.setDrawingCacheEnabled(false);
        // use screenShotAsBitmap as you need
相關文章
相關標籤/搜索