在我的應用程序中,我添加了代碼以允許用戶從圖庫中選擇圖像或使用相機拍攝照片。在右上角選擇攝像機圖標時出現這種情況,並出現一個對話框,其中包含這兩個選項。我只是想知道我將如何添加一個圖標,將用作按鈕。因此,例如,當對話框出現時,我想要一個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