2

タイトルバーのないカスタムダイアログを作成しようとしています.SOの提案に従って、次のことを行います

propDiag = new Dialog(this);
propDiag.requestWindowFeature(Window.FEATURE_NO_TITLE);
propDiag.setContentView(R.layout.property_daig);

ここに私のxmlの一部があります

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:background="@drawable/background"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:orientation= "horizontal">
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="fill_parent" android:orientation= "vertical" android:layout_weight="1" >

                   //COUPLE OF buttons

        </LinearLayout>
        <View android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="0.5" ></View>
        <LinearLayout android:layout_width="wrap_content"
            android:layout_height="fill_parent" android:orientation= "vertical"  android:layout_weight="1"  >
                       //COUPLE OF buttons
            </LinearLayout>
    </LinearLayout>

レイアウトが台無しになり、すべてが左右に最大にプッシュされるという問題

requestWindowFeature なしでそれを行うと、タイトルが表示されることを除いて、すべてが素晴らしいです!.

誰かが解決策を説明して推奨できますか? ありがとう

4

2 に答える 2

3

以下のコードを参照してください。

背景画像はありませんが、アイコン画像を配置して以下のコードを実行しました。

出力のスクリーンショットも添付しています。

コード:

 Button test = (Button) findViewById(R.id.button1);

    test.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
             final Dialog dialog = new Dialog(MainActivity.this);
             dialog.getWindow();
             dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
             dialog.setContentView(R.layout.property_daig);

             dialog.show();

        }

    });

出力:

ここに画像の説明を入力

それがあなたを助けることを願っています。

コーディングをお楽しみください。:)

于 2012-11-09T07:31:33.880 に答える
0
Try this    

            final Dialog dialog = new Dialog(context);
                    dialog.getWindow();
                    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                    dialog.setContentView(R.layout.custom_dialog);

                    TextView customText = (TextView)dialog.findViewById(R.id.customDialogTitletext);
                    customText.setText(text);
                    customText.setTypeface(tf);
                    Button btnOk = (Button) dialog.findViewById(R.id.buttonOk);
                    btnOk.setOnClickListener(new OnClickListener() {
                        @Override
                        public void onClick(View arg0) {
                            dialog.dismiss();
                        }
                    });
                    dialog.show();

                }

問題が解決したかどうかをお知らせください。

于 2012-11-09T06:14:57.737 に答える