ボタンをクリックすると、画面の中央にポップアップ ウィンドウが表示され、ランダムな画像が表示されるプログラムを作成しています。次に、ポップアップ ウィンドウをクリックすると、ポップアップが閉じます。
私の質問これは可能ですか?もしそうならどのように?
はい、できません。そのためには、イメージビューを含むレイアウトを膨張させ、目的のオブジェクトをクリックしたときにそれを呼び出すカスタム アラート ダイアログを作成する必要があります。また、閉じるボタンを AlertDialog に追加して、onlick リスナーを設定する必要があります。
はい、次のようなものを使用できます。
Dialog confirmDeleteDialog = new Dialog(this);
confirmDeleteDialog.setContentView(R.layout.custom_message_dialog);
//This allows dialog to be closed with back button
confirmDeleteDialog.setCancelable(true);
//DisplayMetrics will get the screen dimensions and allow you to
//declare a center point
DiaplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int screenHeight = displaymetrics.heightPixels; //Divide by 2 to get mid
int screenWidth = displaymetrics.widthPixels; //Divide by 2 to get mid
Button closeButton = (Button) confirmDeleteDialog.findViewById(R.id.close_button);
closeButton.setOnClickListener(this);
confirmDeleteDialog.show();
custom_message_dialog.xml - 次のようになります。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:id="@+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"/>
</RelativeLayout>
クリックリスナー
public void onClick(View v) {
if(v == closeButton){
confirmDeleteDialog.dismiss();
}}