android-dialog 相关问题

对话框的基类。 Android中的对话框是一个小窗口,提示用户做出决定或输入其他信息。对话框不会填满屏幕,通常用于需要用户在继续操作之前执行操作的模态事件。

windowBackground 上的对话框自定义状态?

是否可以让我的 android:windowBackground 可绘制对象接收我添加的自定义属性? 对于背景,我有自定义视图,我可以覆盖 onCreateDrawableState。对于对话框来说,那是...

回答 1 投票 0

单击按钮时更改对话框内的按钮属性

我有一个单击按钮后打开的对话框。对话框内部包含多个按钮,但为了简单起见,我只关注“太阳”按钮。理想的...

回答 1 投票 0

按下 home 键进入 onResume 状态时,对话框不显示 android 10-Hander 问题

我有一个按钮来显示对话框。当我单击示例应用程序中的对话框按钮时,几秒钟后立即按下主页按钮。 打开另一个应用程序,按主页...

回答 1 投票 0

Jetpack Compose 对话框不显示灰色叠加层

不确定我是否遗漏了一些明显的东西,但是当显示对话框时,我无法在父屏幕中获取灰色覆盖背景。使用此代码创建一个全新的应用程序: 主活动类:

回答 1 投票 0

recyclerview smoothscroll 不适用于对话框

我的申请流程: stocker片段: 使用条码扫描仪输入条码 如果之前已经扫描过条形码,则平滑滚动到现有条形码并显示对话框模式以编辑数量。 当用户...

回答 1 投票 0

为什么 Android 自定义对话框会全屏显示

我正在尝试创建自定义对话框。 基本布局(我也尝试过各种修改后的布局): 我正在尝试创建自定义对话框。 基本布局(我也尝试过各种修改后的布局): <RelativeLayout android:layout_width="match_parent" android:layout_height="wrap_content" > <TextView android:id="@+id/title" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:layout_alignParentTop="true" android:background="@color/dialogHeaderBackground" android:gravity="center" android:minHeight="@dimen/minHeightDialogTitle" android:text="" android:textStyle="bold" /> <TextView android:id="@+id/message" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentLeft="true" android:layout_below="@+id/title" android:layout_marginTop="5dp" android:text="" /> <LinearLayout android:id="@+id/loutButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_below="@+id/message" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:orientation="horizontal" > <Button android:id="@+id/btnNeutral" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="" /> <Button android:id="@+id/btnNegative" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="" /> <Button android:id="@+id/btnPositive" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_weight="1" android:text="" /> </LinearLayout> </RelativeLayout> Java代码: Dialog dialog = new Dialog(this); // Dialog dialog = new Dialog(this,R.style.Theme_Dialog); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.custom_dialog); Button btnPositive=(Button) dialog.findViewById(R.id.btnPositive); Button btnNegative=(Button) dialog.findViewById(R.id.btnNegative); Button btnNeutral=(Button) dialog.findViewById(R.id.btnNeutral); TextView txvTitle=(TextView)dialog.findViewById(R.id.title); TextView txvMessage=(TextView)dialog.findViewById(R.id.message); ... so on and so forth 我收到以下对话框,该对话框是全屏的,但我不想要: 已经尝试过的解决方案,其结果与上面的屏幕截图相同: Styles.xml 配置 1 | 实现了 Pastebin 代码 Styles.xml 配置 2 | 实现了 Pastebin 代码 Android 开发指南中提供的使用 AlertDialog.Builder 的示例 | 实现的Java代码 我的底层布局都没有使用 MATCH_PARENT 的高度。正如此堆栈溢出中所述 answer 还尝试将窗口设置更改为WRAP_CONTENT,以根据答案此处 | 进行对话在 Pastebin 中实现 Java 代码 还尝试将整个RelativeLayout保留在父级LinearLayout中,请参阅下面的答案中的第3条评论 我唯一能得到像样的对话框是在指定 XML 布局的高度时,就像这样 android:layout_height="150dp" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="150dp" > 指定固定高度时的对话框: 当消息较大时,内容/布局会丢失 当消息较小时,对话框显示得比需要的大,请参见下面的“确定”按钮 不要建议上述(指定固定高度)作为解决方案,因为它效率不高,看起来不太好,也不是动态的,它是静态的。 要指定什么,看起来不错的自定义对话框,也可以自定义? 从线性布局中删除android:layout_alignParentBottom="true"线 <LinearLayout android:id="@+id/loutButton" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:layout_below="@+id/message" android:layout_centerHorizontal="true" android:layout_marginTop="5dp" android:orientation="horizontal" > 从上面的代码中删除android:layout_alignParentBottom="true"并检查。 是的,它发生在相对布局中。 在其谷歌docs中明确提到。 请注意,大小之间不能存在循环依赖关系 relativelayout 及其子级的位置。例如,你 不能有高度设置为 WRAP_CONTENT 的relativelayout 和 子项设置为 ALIGN_PARENT_BOTTOM 当您使用对话框时,您必须根据您的要求使用线性布局。 它绝对会为你工作。 进一步的想法可能不适合你,但我只是提一下供参考 您可以使用java代码来制作固定大小的对话框, 或者您可以从布局参数设置布局边距,以便在不同的屏幕尺寸下保持响应能力。 你还可以做一件事, 获取屏幕尺寸 DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int height = metrics.heightPixels; int width = metrics.widthPixels; 你可以计算新的对话框大小并将其设置为@guobao的答案 DisplayMetrics displayMetrics = new DisplayMetrics(); dialog.getWindow().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); params.width = (new width); params.height = (new height); 询问我是否需要任何进一步的规格。 您可以在对话框中设置此代码 DisplayMetrics displayMetrics = new DisplayMetrics(); dialog.getWindow().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); WindowManager.LayoutParams params = dialog.getWindow().getAttributes(); params.width = (the width you want to set); params.height = (the height you want to set); 这是我遇到同样问题时的方法。 我扩展了 DialogFragment(来自 support.v4 lib) 然后充气: @Override public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); final View view = inflater.inflate(R.layout.dialog_whatever, null); builder.setView(view); return builder.create(); } 这是布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/rounded_corners" android:padding="20dp"> <TextView android:id="@+id/confirm_dialog_text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="16sp" android:textColor="@color/black" android:text="@string/are_you_sure_declining_whatever"/> <LinearLayout android:layout_marginTop="20dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|bottom" android:orientation="horizontal"> <Button android:id="@+id/cancel_action" android:layout_marginRight="10dp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/transparent" android:text="@string/cancel" android:textColor="@color/accent_color"/> <Button android:id="@+id/confirm_action" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="@color/transparent" android:textColor="@color/accent_color" android:text="@string/reject"/> </LinearLayout> </LinearLayout> 这种方法也遵循材料设计指南! 希望对您有帮助 致以诚挚的问候, 佩德罗维奇90

回答 5 投票 0

Kotlin - 程序化创建的Spinner箭头不见了。

以程序化方式创建了一个微调器后,由于某些原因,正常情况下位于右边的下拉箭头没有出现,为什么箭头不见了,如何显示?为什么箭头不见了,怎么显示? spinnerItems ...

回答 1 投票 0

AlertDialog的自定义主题没有被应用。

在themes.xml中设置了AlertDialogs的通用样式。 ... <item name="alertDialogTheme">@styleThemeOverlay...。</root>

回答 1 投票 0

如何设置Android对话框中的ImageView?

我正试图在android对话框中显示一张图片。如果我从图库应用中选择一张图片,它应该在对话框中显示。我已经尝试从图库应用中获取所选图片,并且...

回答 4 投票 2

SetOnClickListener在DialogFragment中不起作用。

我想在DialogFragment中的listview中点击时获得索引,但我什么也没得到... ... 我不知道为什么... 这是OnCreatedDialog,在这里我有setOnClickListener: ...

回答 1 投票 0

谷歌推出前的报告--多个项目有相同的描述。

现在,当一个应用程序的新测试版上传到Play Store时,Google会提供一份 "预启动报告"。我上一次的Pre-Launch报告包含了一个完整的对话框,充满了 "多个项目有相同的......"。

回答 1 投票 0

防止当点击外退按钮时,DialogFragment不显示,而是显示一个要求确认的信息。

我有一个DialogFragment,允许用户输入长消息。默认情况下,如果用户在DialogFragment或后退按钮之外点击,对话框将被删除,用户的输入将丢失。...

回答 1 投票 0

我试图在碎片中显示Dialog,它在上下文中显示一些错误,同样的方法在Activity类中可以正常工作。

这是我的CustomProgressDialog类,其中我使用AysncTask来显示对话框,这段代码在Activity类中工作得很好,但在Fragment中却显示错误,即mDailog = new Dialog(context) ...

回答 1 投票 0

Android导航中没有<对话框>。

从2.1.0版本开始,导航组件中就支持DialogFragment。我是按照官方指南来做的。创建目的地,但是在任何新的版本中都没有这样的选项。I ...

回答 1 投票 0

如何处理对话框中的取消和确定按钮

我想在单击确定按钮时是对话框,它会执行某些操作,与取消按钮覆盖onCreateDialog(savedInstanceState:Bundle?)的乐趣一样:Dialog {val builder = AlertDialog ....

回答 1 投票 1

当我从onDismiss访问另一个片段时,我收到null-Android

我想刷新主要片段。所以我在DialogFragment中使用了onDismiss方法来在其中使用方法refreshFragment来刷新主片段。我不知道这是否是最好的...

回答 1 投票 0

由于打开的对话框,应用在初始化期间崩溃

此崩溃已在我的开发人员控制台中显示了很长时间,并且我无法以任何方式重现它。我有一个以MainActivity开头的应用程序。在onCreate中,某些数据为...

回答 1 投票 -2

为什么我的AlertDialog始终显示?

我试图制作一个应用程序,该应用程序将使用newsapi显示带有recyclerview plus片段的热门新闻。当我启动程序时,警报对话永远不会结束。你能帮助我吗?包com ....

回答 1 投票 1

PreferenceFragments中的DialogPreferences的MaterialAlertDialogBu ilder

在首选项屏幕中,我想使用MaterialComponent的对话框(使用MaterialAlertDialogBu ilder)代替AppCompat的AlertDialog。但是,AppCompat的首选项框架使用...

回答 1 投票 0

如何在Android启动时创建PopupWindow?

可以使用Dialog类,但我不希望这样。相反,我希望通过使用PopupWindow类来完成此操作,该类在启动时会弹出,并在弹出窗口上显示一些消息。我是...

回答 1 投票 2

© www.soinside.com 2019 - 2024. All rights reserved.