LoginSignup
1
2

More than 5 years have passed since last update.

Resource annotationsによる検証

Posted at

Androidの引数にリソースアノテーションを付けることで、リソースに存在するかが検証できる。

before
    private void handleColorChange(int stringResId, int colorResId) {
        int prefColor = pref.getInt(getString(stringResId), 0);

        ...
    }
after
    private void handleColorChange(@StringRes int stringResId, @ColorRes int colorResId) {
        int prefColor = pref.getInt(getString(stringResId), 0);

        ...
    }

AndroidStudioだと以下のように教えてくれる。


スクリーンショット 2017-03-14 21.03.28.png


スクリーンショット 2017-03-14 21.03.49.png

参考

Improve Code Inspection with Annotations | Android Studio

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2