浮动层居中的弹出对话框效果例

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML>
<HEAD>
<TITLE>浮动层居中的对话框效果演示</TITLE>

<STYLE type=text/css>
HTML {
 HEIGHT: 100%
}
BODY {
 HEIGHT: 100%
}
BODY {
 FONT-SIZE: 14px; FONT-FAMILY: Tahoma, Verdana, sans-serif
}
DIV.neat-dialog-cont {
 Z-INDEX: 98; BACKGROUND: none transparent scroll repeat 0% 0%; LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT:

100%
}
DIV.neat-dialog-bg {
 Z-INDEX: -1; FILTER: alpha(opacity=70); LEFT: 0px; WIDTH: 100%; POSITION: absolute; TOP: 0px; HEIGHT: 100%; BACKGROUND-

COLOR: #eee; opacity: 0.7
}
DIV.neat-dialog {
 BORDER-RIGHT: #444 1px solid; BORDER-TOP: #444 1px solid; Z-INDEX: 99; MARGIN-LEFT: auto; BORDER-LEFT: #444 1px solid;

WIDTH: 30%; MARGIN-RIGHT: auto; BORDER-BOTTOM: #444 1px solid; POSITION: relative; TOP: 25%; BACKGROUND-COLOR: #fff
}
DIV.neat-dialog-title {
 PADDING-RIGHT: 0.3em; PADDING-LEFT: 0.3em; FONT-SIZE: 0.8em; PADDING-BOTTOM: 0.1em; MARGIN: 0px; LINE-HEIGHT: 1.2em;

PADDING-TOP: 0.1em; BORDER-BOTTOM: #444 1px solid; POSITION: relative
}
IMG.nd-cancel {
 RIGHT: 0.2em; POSITION: absolute; TOP: 0.2em
}
DIV.neat-dialog P {
 PADDING-RIGHT: 0.2em; PADDING-LEFT: 0.2em; PADDING-BOTTOM: 0.2em; PADDING-TOP: 0.2em; TEXT-ALIGN: center
}

</STYLE>

<SCRIPT type=text/javascript>
function NeatDialog(sHTML, sTitle, bCancel)
{
  window.neatDialog = null;
  this.elt = null;
  if (document.createElement  &&  document.getElementById)
  {
    var dg = document.createElement("div");
    dg.className = "neat-dialog";
    if (sTitle)
      sHTML = '<div class="neat-dialog-title">'+sTitle+
              ((bCancel)?
                '<img src="x.gif" alt="Cancel" class="nd-cancel" />':'')+
                '</div>/n' + sHTML;
    dg.innerHTML = sHTML;

    var dbg = document.createElement("div");
    dbg.id = "nd-bdg";
    dbg.className = "neat-dialog-bg";

    var dgc = document.createElement("div");
    dgc.className = "neat-dialog-cont";
    dgc.appendChild(dbg);
    dgc.appendChild(dg);

    //adjust positioning if body has a margin
    if (document.body.offsetLeft > 0)
      dgc.style.marginLeft = document.body.offsetLeft + "px";

    document.body.appendChild(dgc);
    if (bCancel) document.getElementById("nd-cancel").onclick = function()
    {
      window.neatDialog.close();
    };
    this.elt = dgc;
    window.neatDialog = this;
  }
}
NeatDialog.prototype.close = function()
{
  if (this.elt)
  {
    this.elt.style.display = "none";
    this.elt.parentNode.removeChild(this.elt);
  }
  window.neatDialog = null;
}

function openDialog()
  {

var sHTML =
      '<p><button οnclick="window.neatDialog.close()">关闭!</button></p>';
    new NeatDialog(sHTML, "欢迎光临!", false);
 
}
 
</SCRIPT>
<BODY>
<H1>浮动层居中的对话框效果演示</H1>
<BUTTON οnclick="openDialog()">演示层提示效果</BUTTON>
</BODY></HTML>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
的文本框中。 实现思路: 1. 在布局文件中定义一个LinearLayout,设置orientation为vertical,作为整个对话框的容器。 2. 在LinearLayout中添加一个TextView,用于显示日程选项。 3. 在LinearLayout中添加四个RadioButton,分别表示四个日程选项。 4. 在LinearLayout中添加一个RadioGroup,将四个RadioButton放入其中,设置为单选。 5. 在LinearLayout中添加一个HorizontalLinearLayout,用于显示取消和确定按钮。 6. 在HorizontalLinearLayout中添加一个Button,用于取消操作,设置为左对齐。 7. 在HorizontalLinearLayout中添加一个Button,用于确定操作,设置为右对齐。 8. 在Activity中,使用AlertDialog.Builder创建一个对话框,将布局文件设置为对话框的视图。 9. 在AlertDialog.Builder中设置对话框的标题、图标等属性。 10. 在AlertDialog.Builder中设置对话框的取消按钮和确定按钮的点击事件,分别对应取消操作和确定操作。 11. 在确定按钮的点击事件中,获取选中的RadioButton的文本内容,并将其显示在底部的文本框中。 示代码: 布局文件: ``` <LinearLayout android:id="@+id/dialog_layout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:padding="16dp"> <TextView android:id="@+id/textview" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="请选择日程:" /> <RadioGroup android:id="@+id/radiogroup" android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/radio1" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="日程1" /> <RadioButton android:id="@+id/radio2" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="日程2" /> <RadioButton android:id="@+id/radio3" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="日程3" /> <RadioButton android:id="@+id/radio4" android:layout_width="match_parent" android:layout_height="wrap_content" android:text="日程4" /> </RadioGroup> <View android:layout_width="match_parent" android:layout_height="1dp" android:background="@color/black" /> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="end" android:gravity="center_vertical" android:orientation="horizontal" android:paddingTop="16dp" android:paddingBottom="16dp"> <Button android:id="@+id/btn_cancel" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="取消" android:textColor="@color/black" /> <View android:layout_width="1dp" android:layout_height="match_parent" android:background="@color/black" /> <Button android:id="@+id/btn_ok" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="确定" android:textColor="@color/black" /> </LinearLayout> </LinearLayout> ``` Activity代码: ``` public class MainActivity extends AppCompatActivity { private TextView mTextView; private Button mBtnCancel; private Button mBtnOk; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mTextView = findViewById(R.id.textview); mBtnCancel = findViewById(R.id.btn_cancel); mBtnOk = findViewById(R.id.btn_ok); mTextView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showSelectDialog(); } }); } private void showSelectDialog() { View dialogView = LayoutInflater.from(this).inflate(R.layout.dialog_layout, null); final RadioGroup radioGroup = dialogView.findViewById(R.id.radiogroup); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(dialogView) .setTitle("选择日程") .setIcon(R.mipmap.ic_launcher) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }) .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int checkedId = radioGroup.getCheckedRadioButtonId(); RadioButton radioButton = radioGroup.findViewById(checkedId); String text = radioButton.getText().toString(); mTextView.setText(text); } }); AlertDialog dialog = builder.create(); dialog.show(); } } ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值