gpt4 book ai didi

java - 如何在android中设置自定义对话框的高度和宽度

转载 作者:行者123 更新时间:2023-12-01 16:15:04 29 4
gpt4 key购买 nike

如何将此对话框的自定义高度和宽度直接设置到主 Activity 文件中。我尝试了一种方法,但它只匹配父级的高度和宽度

public void onBackPressed()
{

AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
builder.setTitle(R.string.app_name);
builder.setIcon(R.mipmap.ic_launcher);
builder.setMessage("Please Help Us Grow before leaving!")
.setCancelable(false)
.setPositiveButton("Exit", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton("Share our app", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {

Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "Download it now: https://play.google.com/store/apps/details?id=com.app.package");
sendIntent.setType("text/plain");
sendIntent.setPackage("com.whatsapp");
startActivity(sendIntent);
}
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.copyFrom(alertDialog.getWindow().getAttributes());
layoutParams.width = WindowManager.LayoutParams(100);
layoutParams.height = WindowManager.LayoutParams(100);
alertDialog.getWindow().setAttributes(layoutParams);

最佳答案

您可以将其设置为alertDialog.getWindow().setLayout(600, 400);也可以将其设置为

    WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.copyFrom(alertDialog.getWindow().getAttributes());
layoutParams.width = 150;
layoutParams.height = 500;
layoutParams.x=-180;
layoutParams.y=100;
alertDialog.getWindow().setAttributes(layoutParams);

关于java - 如何在android中设置自定义对话框的高度和宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62421473/

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