gpt4 book ai didi

android - alertdialog 正/负按钮与全屏对话框 fragment 中的父级不匹配

转载 作者:行者123 更新时间:2023-11-30 00:52:20 28 4
gpt4 key购买 nike

在我的 dialogfragment 类的 OnCreateDialog 中,我正在这样做:

AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
inflater=getActivity().getLayoutInflater();
v=inflater.inflate(R.layout.new_spending_fragment_layout,null);
builder.setPositiveButton("Fire", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// FIRE ZE MISSILES!
}
});
builder.setView(v);
return builder.create();

在 dialogfragment 类的 OnStart 中,我正在全屏显示 dialogfragment

Dialog d = getDialog();
if (d!=null){
int width = ViewGroup.LayoutParams.MATCH_PARENT;
int height = ViewGroup.LayoutParams.MATCH_PARENT;
d.getWindow().setLayout(width, height);
}

我希望警报对话框中的正面按钮 (Fire) 显示在底部。

模拟器预览:

enter image description here

我正在膨胀的布局的宽度和高度设置为与父级匹配。

我在膨胀的布局 (R.layout.new_spending_fragment_layout) 中添加了一个空 View ,并将其参数设置为匹配 xml 中的父级,这解决了问题,但我认为这是一个临时的答案。

我还想移除所有边的填充(或间隙)。

最佳答案

试试这个,Dialog with fullscreen screenshot

1 - 创建对话框

Dialog dialog = new Dialog(this, android.R.style.Theme_Light_NoTitleBar); // Replace this line
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_layout);
dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
dialog.show();

2 - dialog_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="Hello this is demo textview"
android:textColor="@color/black"
android:textSize="18sp" />

</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Fire"
android:background="@null"/>

</RelativeLayout>
</RelativeLayout>

关于android - alertdialog 正/负按钮与全屏对话框 fragment 中的父级不匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40786153/

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