Using the system image for “no picture” contacts on Android

筅森魡賤 提交于 2020-01-02 10:59:41

问题


I found this question which is the same problem that I would like to address.

Reading his question and the accepted answer though, it sound like his approach was to pull the actual image file from the resources, embed it in his app and use it as a local resource.

What I'd prefer to be able to do is in the source property for my image, use an ID which would allow me to pull that image from the local system, so that whether my app is running on ICS, HC, GB or Froyo, or if the manufacturer of the device has altered the Android source and included their own image for empty contact photos, that my app would always be using the appropriate one, from the system it is running on at the time.

Something pseudo-coded like:

if(user.NoPhoto) {
    img.src = loadImageFromId(android.R.drawable.ContactWithoutPhoto)  
}

The same way you can use platform styles and strings in your app.
Is there a standard ID for the no-photo contact image, hope hope??


回答1:


Unfortunately that picture is not public.

The only thing you can do is to create the following folders and copy the image from the SDK into your project:

  • For Android 3.0 and later: drawable-xhdpi-v11, drawable-hdpi-v11,drawable-mdpi-v11, and drawable-ldpi-v11.
  • For Android 2.3 :drawable-xhdpi-v9, drawable-hdpi-v9, drawable-mdpi-v9, and drawable-ldpi-v9.
  • For previous versions: drawable-xhdpi, drawable-hdpi, drawable-mdpi, and drawable-ldpi.

The system will select the right image for you and the code below will work fine.

if(user.NoPhoto) {
    img.setImageResource(R.drawable.ic_contact_picture);  
}


来源:https://stackoverflow.com/questions/9366028/using-the-system-image-for-no-picture-contacts-on-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!