Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/232.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/gwt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 自定义对话框正在显示放错位置的内容_Android_Dialog_Android Alertdialog - Fatal编程技术网

Android 自定义对话框正在显示放错位置的内容

Android 自定义对话框正在显示放错位置的内容,android,dialog,android-alertdialog,Android,Dialog,Android Alertdialog,在下面发布的代码中,我是如何自定义我的对话框的。但是应该填充对话框的内容放错了位置,或者不在对话框的相应位置。例如,“报告”一词应与图标一起放置在对话框的上部,但如图所示,它们位于分隔标题和图标以及对话框其余部分的行下。如何纠正 请看一下输出的图像和代码 Java代码: Dialog reportAlertDialog = new Dialog(MeetingPointFix.this); LayoutInflater reportAlertDialogLayoutInf

在下面发布的代码中,我是如何自定义我的
对话框的。但是应该填充
对话框
的内容放错了位置,或者不在
对话框
的相应位置。例如,“报告”一词应与
图标一起放置在
对话框的上部,但如图所示,它们位于分隔
标题
图标
以及
对话框
其余部分的行下。如何纠正

请看一下输出的图像和代码

Java代码:

Dialog reportAlertDialog = new Dialog(MeetingPointFix.this);
            LayoutInflater reportAlertDialogLayoutInflater = LayoutInflater.from(getApplicationContext());
            View reportAlertDialogInflatedView = reportAlertDialogLayoutInflater.inflate(R.layout.report_dialog, null);

            reportAlertDialog.setContentView(reportAlertDialogInflatedView);

            int [] viewsRefsIds = {R.id.reportLocNameValue, R.id.reportLocLatValue, R.id.reportLocLngValue, R.id.reportTimeValue,
                    R.id.reportDateValue, R.id.reportImgTitleValue, R.id.reportImgPathValue
            };
            TextView [] viewsVars = new TextView[viewsRefsIds.length];

            TextView reportAlertDialogMSG = (TextView) reportAlertDialog.findViewById(R.id.reportDialogMessageValue);
            TextView reportAlertDialogTitle = (TextView) reportAlertDialog.findViewById(R.id.reportDialogTitleValue);
            reportAlertDialogMSG.setText(REPORT_ALERT_DIALOG_MSG);
            reportAlertDialogTitle.setText(REPORT_ALERT_DIALOG_TITLE);

            for (int i=0; i<bundleVals.length; i++) {
                viewsVars[i] = (TextView) reportAlertDialog.findViewById(viewsRefsIds[i]);
                viewsVars[i].setText(bundleVals[i]);
            }
            reportAlertDialog.show();
输出:

您应该使用
AlertDialog.setIcon()
AlertDialog.setTitle()
来设置对话框的图标和标题。

您需要将标题设置为alerdialog

 reportAlertDialog.setTitle(REPORT_ALERT_DIALOG_TITLE);// takes charactersequence as param
同样地

 reportAlertDialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawabl‌​e.some_icon); 

您不需要自定义的
ImageView
TextView
如果不希望它们出现在对话框内容部分中,可以将其删除

编辑:

尚未请求该功能


这种情况发生在那些喜欢以编程方式而不是使用xml布局的人身上!您需要设置标题和图标。你还没有这样做,我想我的底图布局将适合“对话”作为一个整体!这是否意味着我需要为对话框标题创建一个layout.xml,为其主体创建另一个layout.xml?很抱歉misunderstanding@Amr不,你不需要所有这些。只需在对话框对象上使用
setTitle()
setIcon()
。并阅读对话框文档。我发布了alertdialog链接sorryAlertDialog.setIcon()不可用,但alertdialog.setTitle()可用。知道为什么吗that@Amr这不是阿勒迪亚洛。这是一种习俗Dialog@Amr
AlertDialog
具有
setIcon()
。但是你有一个自定义对话框我想我的基线布局将适合“对话框”作为一个整体!这是否意味着我需要为对话框标题创建一个layout.xml,为其主体创建另一个layout.xml?很抱歉,误解了AlertDialog.setIcon()不是可用的,但AlertDialog.setTitle()是。知道为什么吗?请参见:
 reportAlertDialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawabl‌​e.some_icon); 
Dialog  dialog = new Dialog(this);
dialog.requestWindowFeature(Window.FEATURE_LEFT_ICON); // request the feature
dialog.setContentView(R.layout.customlayout);
dialog.setTitle("My Title");
dialog.show();
dialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.ic_launcher);
// set the icson