0

私のカスタムヘッダーが必要ですCustomAlert。ダイアログのタイトルのカスタム レイアウトはどうすればよいですか?

Edit2:私は自分のコードを追加しました:

    protected Dialog onCreateDialog(int id) 
        {           
            switch(id)
            {           
            case Dialog_Reset :     
            Dialog dialog=new Dialog(this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.about);  
            dialog.setCanceledOnTouchOutside(true);         
            return dialog;
            }
            return super.onCreateDialog(id);
       } 

ダイアログのデフォルトのヘッダーが気に入らないので、カスタムヘッダーがあることを学びながら、今すぐ削除します。

4

2 に答える 2

1

しかし、「titleId」とは何かわかりません。それは本当に何ですか?タイトルに使用したいのは、私の特別なレイアウト設計ですか?

titleId: タイトル識別子、つまり文字列リソース識別子R.string.app_namestrings.xmlこれらは、見つかったres>valuesフォルダーに追加できます

Android 開発ドキュメント: Dialog.setTitle (int titleId)

文字列リソースの詳細はこちら

于 2013-10-30T11:43:18.323 に答える
0

CustomTitleAlert Dialog利用public AlertDialog.Builder setCustomTitle (View customTitleView)方法を設定できます。

ドキュメントによると

public AlertDialog.Builder setCustomTitle (customTitleView を表示)

カスタム ビュー customTitleView を使用してタイトルを設定します。メソッド setTitle(int) および setIcon(int) は、ほとんどのタイトルで十分ですが、タイトルにさらにカスタマイズが必要な場合に提供されます。これを使用すると、他の方法で設定されたタイトルとアイコンが置き換えられます。

パラメータ customTitleView タイトルとして使用するカスタム ビュー。Set メソッドへの呼び出しの連鎖を可能にするために、この Builder オブジェクトを返します。

LayoutInflater inflater = (LayoutInflater)yourClass.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View yourView= inflater.inflate(R.layout.custom_dialog, null);

AlertDialog.Builder ab= new AlertDialog.Builder(this);
ab.setCustomTitle(yourView);
ab.setMessage(message);
...


 ab.create();
 ab.show();

詳細については、ドキュメントを参照してください

于 2013-10-30T11:56:30.220 に答える