对话框大小填充屏幕,而不是包装内容

时间:2013-12-05 09:54:49

标签: android dialog

我们开发了一款主要在Galaxy Nexus上测试过的应用程序。

现在经过对其他设备的一些测试后,我们发现某些设备(特别是Nexus S)上的标题,某些消息和ok / cancel按钮的对话框不适合“换行内容”。对话是大约80%填补了sreen

看起来像:

//启动
标题
边境
消息
Button1 Button2
“自由空间”
“自由空间”
“自由空间”
//结束

使用过的库是https://github.com/inmite/android-styled-dialogs

有人知道这种情况???

在我们看来,看起来很可怕

应用程序可以在德国,瑞士和奥地利国家的游戏店中找到,名为“Narbage” (https://play.google.com/store/apps/details?id=com.edelapps.narbage

也许这是android构建版本的问题< 4.3

感谢 汤姆

2 个答案:

答案 0 :(得分:0)

    final Dialog dialog = new Dialog(ctx, android.R.style.Theme_Translucent_NoTitleBar);

    LinearLayout linearLayout = new LinearLayout(ctx);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setBackgroundResource(com.example.e_mbmpphe.R.drawable.popupbackground);
    linearLayout.setPadding(10, 10, 10, 10);

    TextView logoTxt = new TextView(ctx);
    logoTxt.setTextSize(20);
    logoTxt.setTypeface(Typeface.SERIF);
    logoTxt.setTextColor(Color.BLACK);

    TextView lineTxt = new TextView(ctx);
    TextView lineTxtup = new TextView(ctx);

    lineTxt.setBackgroundResource(com.example.e_mbmpphe.R.drawable.linebackground);
    lineTxtup.setBackgroundResource(com.example.e_mbmpphe.R.drawable.linebackground);

    TextView errormsgTxt = new TextView(ctx);
    errormsgTxt.setTypeface(Typeface.SERIF);
    errormsgTxt.setTextColor(Color.BLACK);
    errormsgTxt.setTextSize(29);

    LinearLayout linearLayout2 = new LinearLayout(ctx);
    linearLayout2.setOrientation(LinearLayout.HORIZONTAL);
    Button saveBtn = new Button(ctx);
    saveBtn.setTextSize(20);
    saveBtn.setTypeface(Typeface.SERIF);
    saveBtn.setTextColor(Color.BLACK);
    saveBtn.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 4f));

    Button cancelBtn = new Button(ctx);
    cancelBtn.setTextSize(20);
    cancelBtn.setTypeface(Typeface.SERIF);
    cancelBtn.setTextColor(Color.BLACK);
    cancelBtn.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 4f));

    linearLayout.addView(logoTxt);
    linearLayout.addView(lineTxtup);
    linearLayout.addView(errormsgTxt);
    linearLayout.addView(lineTxt);
    linearLayout.addView(linearLayout2);
    linearLayout2.addView(saveBtn);
    linearLayout2.addView(cancelBtn);

        logoTxt.setText(" Alert !!!");
        errormsgTxt.setText("Are you sure you want to Restore "+workTitle+ " Work");


    saveBtn.setText("Yes");
    cancelBtn.setText("No");
    saveBtn.setOnClickListener(new View.OnClickListener() { 
        public void onClick(View v) {
            db.upadteremoveWorkFromWorkListStatus(workId, "false");
            fillWork();
            dialog.dismiss();
        }


    });

    cancelBtn.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            dialog.dismiss();

        }
    });

    dialog.setContentView(linearLayout);
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    lp.copyFrom(dialog.getWindow().getAttributes());
    lp.width = LayoutParams.WRAP_CONTENT;
    lp.height = LayoutParams.WRAP_CONTENT;
    dialog.getWindow().setAttributes(lp);
    lp.x=-170;
    lp.y=100;
    dialog.show();

答案 1 :(得分:0)

将BaseDialogFragment中的onCreateDialog方法更改为... - >不使用inmite.dialog样式引用。

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Dialog dialog = new Dialog(getActivity());
    dialog.getWindow();
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    return dialog;
}