问题
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
, anddrawable-ldpi-v11
. - For Android 2.3 :
drawable-xhdpi-v9
,drawable-hdpi-v9
,drawable-mdpi-v9
, anddrawable-ldpi-v9
. - For previous versions:
drawable-xhdpi
,drawable-hdpi
,drawable-mdpi
, anddrawable-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