开发者

Using icons from system versus copying them into your project

开发者 https://www.devze.com 2023-03-16 21:08 出处:网络
For common Android icons (such as context menu icons) I typically copy the standard Android i开发者_StackOverflow社区cons into my project. I realized recently that you can also get those icons from th

For common Android icons (such as context menu icons) I typically copy the standard Android i开发者_StackOverflow社区cons into my project. I realized recently that you can also get those icons from the system using android.R.drawable.blablabla. So my question is, is there any reason to prefer one approach over the other?

And if using the system ones is better, how do you access them in XML?

Thanks!


You can access them by prepending '@android', i.e.:

<Image android:src="@android:drawable/ic_menu_add" android:layout_height="wrap_content" android:layout_width="wrap_content"/>

If you use the system resources you'll have less control about how exactly the ressource will look like. You will get the ressource installed on the current device, and that differs throughout devices, manufactures and android version.


Reference system images

The general advice is to reference system images where possible

  • GOOD: Will match the OS level (some icons change during the iterations)
  • GOOD: Will play well with stock UI and custom Themes
  • GOOD: No need to show the Apache2 license (IANAL)
  • BAD: May break the appearance of your app
  • BAD: Limited to officially exported images

As you can see there are downsides to both solutions. You can, for example, use the black and white Browser icon to symbolize a link to the browser. The icon is not officially exported, you thus need to copy it. But you have to obey the license of the used artwork in this case. This includes an attribution to content created by the Android Open Source Project (see your copy of the License file for details)

Usage in XML

You can always use the android: prefix to reference system icons in your app. An example would be

@android:drawable/ic_menu_add

This applies to strings and other resources as well, like the "OK" text.


It's better to copy them into your project, as the system icons are not guaranteed to remain in future builds or keep the same name. Copying them into your project gives your app a consistent look and feel across builds and gives you the peace of mind that your icons will always work.

0

精彩评论

暂无评论...
验证码 换一张
取 消