gpt4 book ai didi

android - 自定义对话框显示错位的内容

转载 作者:行者123 更新时间:2023-11-29 21:08:08 26 4
gpt4 key购买 nike

在下面发布的代码中,我是如何自定义我的 Dialog 的。但是本应填充Dialog 的内容放错了位置,或者不在Dialog 的相应位置。例如,单词“Report”应该与 icon 一起放置在 dialog 的上部,但正如您在图片中看到的,它们被放置在下方分隔 titleicon 上半部分以及 dialog 其余部分的线。如何纠正?

请同时查看输出图像和代码。

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();

日志:

05-24 10:35:32.357: E/AndroidRuntime(5673): FATAL EXCEPTION: main
05-24 10:35:32.357: E/AndroidRuntime(5673): Process: com.example.meetingpointlocator_03, PID: 5673
05-24 10:35:32.357: E/AndroidRuntime(5673): java.lang.RuntimeException: The feature has not been requested
05-24 10:35:32.357: E/AndroidRuntime(5673): at com.android.internal.policy.impl.PhoneWindow.getDrawableState(PhoneWindow.java:3200)
05-24 10:35:32.357: E/AndroidRuntime(5673): at com.android.internal.policy.impl.PhoneWindow.setFeatureDrawableResource(PhoneWindow.java:1208)
05-24 10:35:32.357: E/AndroidRuntime(5673): at android.app.Dialog.setFeatureDrawableResource(Dialog.java:1049)
05-24 10:35:32.357: E/AndroidRuntime(5673): at com.example.meetingpointlocator_03.MeetingPointFix$4.report(MeetingPointFix.java:296)
05-24 10:35:32.357: E/AndroidRuntime(5673): at com.example.meetingpointlocator_03.MeetingPointFix$4.onClick(MeetingPointFix.java:240)
05-24 10:35:32.357: E/AndroidRuntime(5673): at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
05-24 10:35:32.357: E/AndroidRuntime(5673): at android.os.Handler.dispatchMessage(Handler.java:102)
05-24 10:35:32.357: E/AndroidRuntime(5673): at android.os.Looper.loop(Looper.java:136)
05-24 10:35:32.357: E/AndroidRuntime(5673): at android.app.ActivityThread.main(ActivityThread.java:5017)
05-24 10:35:32.357: E/AndroidRuntime(5673): at java.lang.reflect.Method.invokeNative(Native Method)
05-24 10:35:32.357: E/AndroidRuntime(5673): at java.lang.reflect.Method.invoke(Method.java:515)
05-24 10:35:32.357: E/AndroidRuntime(5673): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
05-24 10:35:32.357: E/AndroidRuntime(5673): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
05-24 10:35:32.357: E/AndroidRuntime(5673): at dalvik.system.NativeStart.main(Native Method)

输出: enter image description here

最佳答案

你需要给alerdialog设置标题

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

同理

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

http://developer.android.com/reference/android/app/Dialog.html

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

编辑:

The feature has not been requested

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

关于android - 自定义对话框显示错位的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23845580/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com