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.drawable.some_icon);
您不需要自定义的ImageView
和TextView
如果不希望它们出现在对话框内容部分中,可以将其删除
编辑:
尚未请求该功能
这种情况发生在那些喜欢以编程方式而不是使用xml布局的人身上!您需要设置标题和图标。你还没有这样做,我想我的底图布局将适合“对话”作为一个整体!这是否意味着我需要为对话框标题创建一个layout.xml,为其主体创建另一个layout.xml?很抱歉misunderstanding@Amr不,你不需要所有这些。只需在对话框对象上使用setTitle()
和setIcon()
。并阅读对话框文档。我发布了alertdialog链接sorryAlertDialog.setIcon()不可用,但alertdialog.setTitle()可用。知道为什么吗that@Amr这不是阿勒迪亚洛。这是一种习俗Dialog@AmrAlertDialog
具有setIcon()
。但是你有一个自定义对话框我想我的基线布局将适合“对话框”作为一个整体!这是否意味着我需要为对话框标题创建一个layout.xml,为其主体创建另一个layout.xml?很抱歉,误解了AlertDialog.setIcon()不是可用的,但AlertDialog.setTitle()是。知道为什么吗?请参见:
reportAlertDialog.setFeatureDrawableResource(Window.FEATURE_LEFT_ICON,R.drawable.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