首页 > 其他分享 >一个典型的从下部弹上来的Dialog

一个典型的从下部弹上来的Dialog

时间:2023-04-06 22:42:48浏览次数:36  
标签:context 弹上来 void 下部 Dialog import android true public


典型的看图



一个典型的从下部弹上来的Dialog_xml


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import cn.tangdada.tangbang.R;

public class SimpleBottomDialog extends Dialog
{

    private Context context;

    public SimpleBottomDialog(Context context)
    {
        this(context, R.style.Theme_Dialog_From_Bottom);
        // TODO Auto-generated constructor stub
    }

    public SimpleBottomDialog(Context context, int theme)
    {
        super(context, theme);
        // TODO Auto-generated constructor stub
        this.context = context;
        init();
    }

    private void init()
    {
        this.setCanceledOnTouchOutside(true);
        this.setCancelable(true);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_simple_bottom);

        initViews();
        initValues();
    }

    private void initViews()
    {
        findViewById(R.id.btn_0).setOnClickListener(clickListener);
        findViewById(R.id.btn_1).setOnClickListener(clickListener);

    }

    private void initValues()
    {
        // 不能写在init()中
        Window window = getWindow();
        WindowManager.LayoutParams lp = window.getAttributes();
        DisplayMetrics dm = context.getResources().getDisplayMetrics();
        lp.width = dm.widthPixels;//让dialog的宽占满屏幕的宽
        lp.gravity = Gravity.BOTTOM;//出现在底部
        window.setAttributes(lp);

    }

    View.OnClickListener clickListener = new View.OnClickListener()
    {

        @Override
        public void onClick(View v)
        {
            // TODO Auto-generated method stub
            switch (v.getId())
            {
                case R.id.btn_0:
                    if (onOKClickListener != null)
                    {
                        onOKClickListener.onOKClick(v);
                    }
                    dismiss();
                    break;
                case R.id.btn_1:
                    dismiss();
                    break;

                default:
                    break;
            }
        }

    };

    private OnOKClickListener onOKClickListener;

    public interface OnOKClickListener
    {
        public void onOKClick(View v);
    }

    public void setOnOKClickListener(OnOKClickListener onOKClickListener)
    {
        this.onOKClickListener = onOKClickListener;
    }
}




布局:


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:orientation="vertical"
    android:padding="@dimen/padding" >

    <Button
        android:id="@+id/btn_0"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="@dimen/margin"
        android:background="@drawable/bg_btn_white_blue_with_corner"
        android:padding="@dimen/padding"
        android:text="@string/send" />

    <Button
        android:id="@+id/btn_1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/bg_btn_white_blue_with_corner"
        android:padding="@dimen/padding"
        android:text="@string/cancel" />

</LinearLayout>




样式:


<style name="Theme_Dialog_From_Bottom" parent="@android:style/Theme.Dialog">
        <item name="android:windowFrame">@null</item>
        <item name="android:windowNoTitle">true</item>
        <item name="android:windowIsFloating">true</item>
        <item name="android:windowIsTranslucent">true</item>
        <item name="android:windowAnimationStyle">@style/dialog_animation</item>
        <item name="android:backgroundDimEnabled">true</item>
        <item name="android:windowBackground">@android:color/transparent</item>
    </style>

    <style name="dialog_animation" parent="@android:style/Animation.Dialog">
        <item name="android:windowEnterAnimation">@anim/push_bottom_in</item>
        <item name="android:windowExitAnimation">@anim/push_bottom_out</item>
    </style>




两个动画文件:


push_bottom_in.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="400"
        android:fromYDelta="100%p"
        android:toYDelta="0" />

    <alpha
        android:duration="400"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

</set>




push_bottom_out.xml


<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >

    <translate
        android:duration="400"
        android:fromYDelta="0"
        android:toYDelta="50%p" />

    <alpha
        android:duration="400"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />

</set>


  • 一个典型的从下部弹上来的Dialog_android_02

  • 大小: 30.7 KB
  • 查看图片附件

标签:context,弹上来,void,下部,Dialog,import,android,true,public
From: https://blog.51cto.com/u_5454003/6174206

相关文章

  • 简单实现可以多选的ProductListDialog<T>
    只是一个范例,是为了代码快速迭代而写的使用了listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);效果图importjava.util.ArrayList;importjava.util.List;importandroid.app.Dialog;importandroid.content.Context;importandroid.os.Bundle......
  • 基于WheelView自定义的DatePickerDialog
    本人利用WheelView写的一个DatePickerDialog(还有一个TimePickerDialog,本人忘了在写在哪个项目里了,等找到了也贴上来)先看图,有个直观的了解DatePickerDialog代码:importjava.util.Calendar;importcom.widget.wheel.NumericWheelAdapter;importcom.widge......
  • FolderBrowserDialog类实现选择打开文件
    privatevoidbutton1_Click(objectsender,EventArgse){FolderBrowserDialogdilog=newFolderBrowserDialog();dilog.Description="请选择文件夹";if(dilog.ShowDialog()==DialogResult.OK||dilog.ShowDialo......
  • Prism源码分析--IDialogService
    1,首先看下接口提供了哪些方法 2,逻辑的实现类是DialogService,业务逻辑层一般使用方法如下   3,上面使用的方法实际上是IDialogService的一个扩展方法,扩展方法调用了实现类中的Show方法   4,Show方法内又调用了ShowDialogInternal   5,ShowDialogInternal......
  • Ubuntu服务器下部署Springboot项目教程
    IDEA是Springboot服务器后台的开发工具,软件自备,项目自备。1.进入IDEA,点击IDEA最右边的Maven->Lifecycle->package2.打包之后,你可以在项目文件夹的target文件夹里面看到一个x......
  • c#后台执行js弹窗art.dialog,成功后跳转页面
     stringmsbox="<script>dialog({title:'修改成功',content:'修改成功',width:'180px',height:'100px',okValue:'确定',ok:function(){";          ......
  • element-plus的el-dialog对话框组件自定义样式未生效
    修改dialog组件样式必须在非scoped环境下,再加一个style标签,并给需要加的dialog一个类名eg:createDialog<stylelang="scss"scoped>...</style><stylelang="scss">.crea......
  • winform用show实现showdialog的模态化效果
    一、Show与ShowDialog众所周知在c#中有两种显示窗口的方式:模态显示(showdialog)与非模态显示(show),模态显示会阻塞调用窗口的所有消息响应,在调用ShowDialog方法后,直到关闭对......
  • delphi 保存FontDialog设置到ini文件
    public{Publicdeclarations}procedureSetIniFile(Strtitle,StrName:String;FileName:String);functionReadIniFile(Strtitle,StrName:String):......
  • Linux环境下部署tomcat服务-单项目部署
    一、上传tomcat安装包并解压1. apache-tomcat-8.5.38.zip2.安装包可以存放任意目录二、将被测项目放入webapps目录下三、修改被测项目中的配置文件信息......