我试着这样做:插入来自图库的图像上的按钮,Android的
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1 && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Bitmap bmp = BitmapFactory.decodeFile(picturePath);
b[1].setCompoundDrawablesWithIntrinsicBounds(null, new BitmapDrawable(bmp), null, null);
}
,但它不会设置图像,不管是什么。我尝试了好几种不同的方法太像使用的ImageButton,而不是一个按钮的使用:
imageButton.setImageBitmap(bmp)
画廊打开罚款,并且回调来onActivityResult(...) 但图像不会出现在按钮,我有一个按钮阵列。
但是图像不会出现在按钮上...您想要在按钮上显示图像? – Numair
是的,我希望图像在按钮上。 – lolcat
你试过ImageButton.setImageUri(selectedImage)吗?不过,我不确定它是否可以处理内容提供商uris。 – bigstones