在我的应用程序中,我添加了代码以允许用户从图库中选择图像或使用相机拍摄照片。在右上角选择摄像机图标时出现这种情况,并出现一个对话框,其中包含这两个选项。我只是想知道我将如何添加一个图标,将用作按钮。因此,例如,当对话框出现时,我想要一个android画廊图标的图像,当您选择将您带入画廊。还希望使用不同字体颜色的文字“图库”。Android Studio - 设置图标并更改字体颜色
下面是用于创建选项
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == R.id.launch_voip_call) {
Utils.startCall(this, contact);
return true;
} else if (item.getItemId() == R.id.launch_camera) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Pick Image from")
.setPositiveButton("Camera", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
//camera intent
Intent cameraIntent = new Intent(ConversationActivity.this, CameraActivity.class);
cameraIntent.putExtra("EXTRA_CONTACT_JID", contact.getJid());
startActivity(cameraIntent);
}
})
.setNegativeButton("Gallery", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
Intent intent = new Intent();
// Show only images, no videos or anything else
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
// Always show the chooser (if there are multiple options available)
startActivityForResult(Intent.createChooser(intent, "Select Picture"), PICK_IMAGE_REQUEST);
}
});
AlertDialog alert = builder.create();
alert.show();
}
return false;
}
你想在画廊屏幕上显示你自己的图库和字体吗? –
是的,我想显示自己的图标,目前为了进入画廊...您选择当前只是文本的'图库',在弹出选项框中选择摄像机图标时。所以,而不是文字,我想我自己的画廊图标出现。谢谢 –
使用onShow事件:http://stackoverflow.com/a/20830973/1129995 – Zaki