2011-07-14 13 views
0

クリック可能なダイアログボックスのタイトルにアイコンを付けることができるかどうか質問したいと思います。 次の行を使用して、ダイアログボックスの左側にタイトル「新規連絡先」を設定し、右側にアイコンを設定しました。だから、このアイコン(x5)は何らかの形でクリック可能になりますか?閉じるボタンのように機能したい。ダイアログボックスのタイトルのクリック可能なアイコン

dialog.requestWindowFeature(Window.FEATURE_RIGHT_ICON);

 dialog.setTitle("New Contact     "); 
    dialog.setContentView(R.layout.pop_up_new_contact);//loads the layout we have already create pop_up_new_contact.xml 
    dialog.setFeatureDrawableResource(Window.FEATURE_RIGHT_ICON, R.drawable.x5);//adds an icon in the left of the Title. 
    dialog.setCancelable(true); 

答えて

0

カスタムダイアログを作成することをお勧めします。しかし、Androidユーザーのようにクローズボタンとして使用するUXの悪いデザインは、同じ行動をとってバックバックに慣れています。

0

これはあなたが求めているものではありませんが、バックボタンのすべてを探している場合は私には起こります。これは動作します。

dialog.setButton(getText(R.string.cancel), new DialogInterface.OnClickListener() 
{ 
    public void onClick(DialogInterface dialog, int whichButton) { } 
}); 
1

解決策を見つけました!誰かがそれを必要とする場合に備えて、これは私がやったことです。

@Override 
protected Dialog onCreateDialog(int id) {//creates the dialog 

final Dialog dialog = new Dialog(this); 

dialog.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//adds in the dialog box a frame for the custom title 

@Override 
protected Dialog onCreateDialog(int id) {//creates the dialog 
    final Dialog dialog = new Dialog(this); 

    dialog.requestWindowFeature(Window.FEATURE_CUSTOM_TITLE);//adds in the dialog box a frame for the custom title 

    //dialog.setTitle("New Contact");//sets the title of the dialog box 

    dialog.setContentView(R.layout.pop_up_new_contact);//loads the layout we have already create pop_up_new_contact.xml 
    dialog.getWindow().setFeatureInt(Window.FEATURE_CUSTOM_TITLE, R.layout.custom_title_dialog_box);//sets our custom title(custom_title_dialog_box.xml) as the current title of the dialog box. The custom_title_dialog_box.xml contains a TextView with id: title_new_contact and an ImageView with id: x1_button. 

    dialog.setCancelable(true);//close the dialog box when the back key is pushed. 

    ImageView x1_button = (ImageView)dialog.findViewById(R.id.x1_button); 

    x1_button.setOnClickListener(new View.OnClickListener(){ 
     public void onClick(View View3) { 
     dialog.dismiss(); 
     } 
    }); 

    return dialog; 
} 

多分それは最高の解決策ではありませんが、少なくとも機能します。

+0

私は ' DialogFragment''内部AlertDialog'、およびコンパイラが私を投げる 'android.util.AndroidRuntimeExceptionを使用しています:あなたは実際にあなたが今 '新しいAlertDialog.Builderを(使用すること – murt

+0

features'他のタイトルとカスタムのタイトルを組み合わせることはできません...)。setCustomTitle(R.layout.custom_title) ' https://stackoverflow.com/a/9430855/2163045 – murt

関連する問題