如何在android中的对话框中摆脱恼人的标题

时间:2012-11-28 12:23:53

标签: android dialog

如何在android中的对话框中摆脱恼人的标题?

就像我读到对话框一样:

data myDialog = new data(context);
myDialog.show();

这是我的对话

public class data extends Dialog {
    public data(Context context) {
        super(context);
    }
    TextView txtName;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.data);
        setTitle("annoying  title");
        Button btnClose;
        Button btnexit;

        txtName = (TextView)findViewById(R.id.txtName);
        txtName.setText(MyParam.Fname_Lname);
        //txtName.setText(MyParam.zPhone);


        btnClose = (Button) findViewById(R.id.btnDiel);
        btnClose.setOnClickListener(new Close());

        btnexit = (Button) findViewById(R.id.btnSMS);
        btnexit.setOnClickListener(new exit());
    }

    private class Close implements android.view.View.OnClickListener {
        public void onClick(View v) {
            data.this.dismiss();
        }
    }

    private class exit implements android.view.View.OnClickListener {
        public void onClick(View v) {
             data.this.dismiss();
        }
    }

我尝试删除此行setTitle("annoying title");

我试试这个

myDialog.getWindow();
myDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);

但如果我这样做,我会将对话框视为垂直线

2 个答案:

答案 0 :(得分:3)

之前请尝试此dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.mydialog);

您只需在不想显示标题栏的活动中定义主题android:theme="@android:style/Theme.Light.NoTitleBar"

了解更多信息Custom Dialog without title and border

Android Dialog: Removing title bar

答案 1 :(得分:0)

我不知道你在哪里声明了类型数据,但是在你调用Dialog构造函数的地方那样做:

new Dialog(getContext(),android.R.style.Theme_Translucent_NoTitleBar);