Useful Android system resources

后端 未结 4 729
醉话见心
醉话见心 2020-12-12 15:11

Android comes with lots of system resources (android.R) that can be used to save you time and make your application lighter.

For example, I recently dis

4条回答
  •  轮回少年
    2020-12-12 15:39

    As CommonsWare mentioned, you don't have to download the Android source repository to inspect the resources; just go to /platforms/android-X.X/data/res/. However, if you start using these you will quickly become disappointed to find that most of them are not available through the android.R class. Most of the time I have to import them into my Eclipse workspace anyway. :-(

    My favorite resources are the drawables that show differently based on a control's focused/pressed/disabled states (like android.R.drawable.btn_default). I use those or tweak them to create custom buttons for my apps. As you can see if you look at /data/res/drawable/btn_default.xml, they are defined as a XML element, which gets inflated into a StateListDrawable at runtime. You could also create your own StateListDrawables and they're super useful, both as View backgrounds and as a button's "compound drawable" (see TextView.setCompoundDrawables()).

提交回复
热议问题