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 回答