alertDialog的底部显示

第一步创建alertdialog

  Alertdialog.builder builder=new AlertDialog.builder(this);

View view=layoutInflater.from(this).inflate(布局文件,null);

builder.setView(view);

AlertDialog   dialog=builder.creat();

 dialog.show();

以上就是显示AlertDialog的所用步骤

接下来就是底部显示的重要代码

 Window window = dialog.getWindow();
                window.setGravity(Gravity.BOTTOM);
                WindowManager m = getWindowManager();
                Display d = m.getDefaultDisplay(); //为获取屏幕宽、高
                WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); //获取对话框当前的参数值
                p.width = d.getWidth(); //宽度设置为屏幕
                dialog.getWindow().setAttributes(p); //设置生效

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要实现这个功能,可以使用Android Studio的AlertDialog和ListView。首先,创建一个字符串数组来存储单选对话框中的选项内容。然后,在AlertDialog中使用setSingleChoiceItems方法将选项显示在ListView中。接下来,在AlertDialog的setPositiveButton方法中添加代码来获取所选选项的索引,并将其内容显示底部的浮动文本中。 以下是示例代码: ``` final String[] options = {"Option 1", "Option 2", "Option 3"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Choose an option"); builder.setSingleChoiceItems(options, -1, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // do nothing } }); builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int selectedPosition = ((AlertDialog) dialog).getListView().getCheckedItemPosition(); if (selectedPosition != -1) { String selectedOption = options[selectedPosition]; // display selected option in floating text view TextView floatingTextView = findViewById(R.id.floating_text_view); floatingTextView.setText(selectedOption); floatingTextView.setVisibility(View.VISIBLE); } } }); builder.setNegativeButton("Cancel", null); AlertDialog alertDialog = builder.create(); alertDialog.show(); ``` 在这个例子中,我们在AlertDialog的setPositiveButton方法中获取ListView中被选中的选项的索引。如果用户选中了一个选项,我们将该选项的内容显示底部的浮动文本视图中。这里使用了一个TextView来实现浮动文本视图,但你可以使用任何你想要的视图。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值