Android实现从底部弹出的Dialog

Android---底部弹窗之BottomSheetDialog 通过BottomSheetDialog简单实现底部弹窗。比如,经常用到的更换头像操作。 阅读详情

1.点击按钮(按钮的点击事件在此不在赘述,接下来直接写底部弹框的实现方式和样式的设计)

2.弹框

Dialog  dialog = new Dialog(context, R.style.ActionSheetDialogStyle);
                //填充对话框的布局
                inflate = LayoutInflater.from(context).inflate(R.layout.dialog_layout, null);
               // setCancelable(iscancelable);//点击外部不可dismiss
                //setCanceledOnTouchOutside(isBackCanCelable);
                //初始化控件
                spinner = (Spinner) inflate.findViewById(R.id.sp);
                beizhu = (TextView) inflate.findViewById(R.id.beizhu);
                btn_cancel = (Button) inflate.findViewById(R.id.btn_cancel);
                btn_ok = (Button) inflate.findViewById(R.id.btn_ok);
                //将布局设置给Dialog
                taskProgress.setContentView(inflate);
                //获取当前Activity所在的窗体
                Window dialogWindow = taskProgress.getWindow();
                //设置Dialog从窗体底部弹出
                dialogWindow.setGravity(Gravity.BOTTOM);
                //获得窗体的属性
                WindowManager.LayoutParams lp = dialogWindow.getAttributes();
                //如果没有这行代码,弹框的内容会自适应,而不会充满父控件
                lp.width = WindowManager.LayoutParams.MATCH_PARENT;
                lp.y = 40;//设置Dialog距离底部的距离

                //将属性设置给窗体
                dialogWindow.setAttributes(lp);
                dialog .show();//显示对话框

             在需要消失地方直接
             dialog.dismiss();

3.窗口的样式

<style name="ActionSheetDialogStyle" parent="@android:style/Theme.Dialog">

        <!-- 背景透明 -->
        <item name="android:windowBackground">@android:color/transparent</item>
        <item name="android:windowContentOverlay">@null</item>
        <!-- 浮于Activity之上 -->
        <item name="android:windowIsFloating">true</item>
        <!-- 边框 -->
        <item name="android:windowFrame">@null</item>
        <!-- Dialog以外的区域模糊效果 -->
        <item name="android:backgroundDimEnabled">true</item>
        <!-- 无标题 -->
        <item name="android:windowNoTitle">true</item>
        <!-- 半透明 -->
        <item name="android:windowIsTranslucent">true</item>
        <!-- Dialog进入及退出动画 -->
        <item name="android:windowAnimationStyle">@style/ActionSheetDialogAnimation</item>
    </style>
    <!-- ActionSheet进出动画 -->
    <style name="ActionSheetDialogAnimation" parent="@android:style/Animation.Dialog">
        <item name="android:windowEnterAnimation">@anim/actionsheet_dialog_in</item>
        <item name="android:windowExitAnimation">@anim/actionsheet_dialog_out</item>
    </style>

4.窗口出现和消失的效果

对话框出现动画代码:
<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200"
    android:fromYDelta="100%"
    android:toYDelta="0" />

对话框消失的代码:

<?xml version="1.0" encoding="utf-8"?>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
    android:duration="200"
    android:fromYDelta="0"
    android:toYDelta="100%" />

5.弹框的整体布局

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_task_progress"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:background="@drawable/lin_style"
        android:gravity="center_vertical"
        android:orientation="vertical">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal">

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="任务进度"
                android:textSize="17sp" />

            <Spinner
                android:id="@+id/sp"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"></Spinner>

        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="20dp"
            android:focusable="true"
            android:focusableInTouchMode="true"
            android:orientation="horizontal">

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1"
                android:gravity="center"
                android:text="备注"

                android:textSize="17sp" />

            <EditText
                android:id="@+id/beizhu"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="2"
                android:hint="请输入备注" />
        </LinearLayout>

    </LinearLayout>


    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="10dp"
        android:layout_marginTop="5dp"
        android:orientation="horizontal">

        <Button
            android:id="@+id/btn_cancel"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:layout_weight="1"
            android:background="@drawable/button_style"
            android:minHeight="0dp"
            android:minWidth="0dp"
            android:paddingBottom="8dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="8dp"
            android:text="取消"
            android:textColor="#fff" />

        <Button
            android:id="@+id/btn_ok"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:layout_weight="1"
            android:background="@drawable/button_style"
            android:minHeight="0dp"
            android:minWidth="0dp"
            android:paddingBottom="8dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="8dp"
            android:text="确定"
            android:textColor="#fff" />
    </LinearLayout>
</LinearLayout>

6.lin_style样式

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="10dp"></corners>
    <solid android:color="#fff" />
</shape>

7.button_style样式

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <corners android:radius="5dp"></corners>
    <solid android:color="#46b5e9" />
</shape>

6.效果图
这里写图片描述

告别环境配置焦虑:在Win10的Ubuntu子系统里搞定CSAPP实验环境(附32/64位库编译指南) 本文详细介绍了如何在Win10的Ubuntu子系统中搭建CSAPP实验环境,包括WSL 2的安装与配置、32/64位库的编译指南以及高效开发工具链的设置。通过优化WSL性能和使用实用技巧,开发者可以轻松应对CSAPP实验中的环境配置问题,提升学习效率。 阅读详情

相关推荐

亚马逊广告接口 amazon advertising

亚马逊广告接口官方说明:https://advertising.amazon.com/API/docs/en-us/setting-up/account-setup 一:注册aws开发者账号 注册地址:https://developer.amazon.com 二:填写注册资料 三:进入控制台,生成安全配置文件 进入 Login with Amazon 菜单: 创建配置文件: 四:申请广告接入权限 申请地址:https://advertising.amazon.com/zh-cn/about-api

lzy66666的博客 4729

Android代码-方便简洁的BottomDialog,支持任意布局

BottomDialog 中文版 BottomDialog is a bottom dialog layout implemented with DialogFragment,And supports pop-up animation, support any layout Preview Import Maven me.shaohui bottomdialog 1.1.9 pom or Gradle compile 'me.shaohui:bottomdialog:1.1.9' Uasge You can use BottomDialog in two different ways : 1.Use directly BottomDialog A simple three lines of code can be done: BottomDialog.create(getSupportFragmentManager()) .setLayoutRes(R.layout.dialog_layout) // dialog la

Android 底部弹出dialog与动画实现指南

创建自定义Dialog布局是提升Android应用用户交互体验的关键步骤。一个精心设计的Dialog可以增加应用的专业度,同时使用户操作更加便捷。本章将引导您了解如何从零开始创建一个自定义Dialog布局,并实现基础的UI设计。在设计Android应用时,对话框(Dialog)是与用户交互的重要组件之一。自定义Dialog能够提供更丰富的界面表现形式和更灵活的交互方式。为了实现自定义Dialog,我们需要了解其继承关系、构造过程以及事件处理机制。

weixin_36364707的博客 969

Android开源库-BottomDialog两种样式弹框

网上这种底部弹窗一大堆,写这个开源library主要还是自己后面项目集成使用方便。

Tobey_r1的博客 1030

Android 基于BottomSheetDialog 自定义底部弹出Dialog

前言 BottomSheetDialogAndroid 6.0 推出的新控件,即 Base class for Dialogs styled as a bottom sheet 基于Dialog样式的一个底部对话框 但原生控件可扩展性往往满足不了日常开发,于是自己基于它自定义一个Dialog,使用方便,可扩展性高 一、效果 二、使用步骤 1.引入库 implementation 'androidx.recyclerview:recyclerview:1.1.0' 2.代码

X_sunmmer的博客 9608

Dialog对话框。Spinner下拉框,Dialog对话框,超级详细解答!!!!!

需要注意的是找自己布局中的控件时候经常报NullpointException,原因也很简单就是没有使用加载的布局.findViewbyId();同样,和单元对话框一样.setMultiChoiceItems(items,checkedItems,listener)//第一个参数设置的是你需要单选的内容来源,第二个参数设置的是默认选红的选项,因为是多选,所以可以使用数组来指定。即可,第一个参数即要显示item的数组,第二个参数也就是点击item后的监听事件就很好解决啦。第二个参数设置默认选中哪一项。...

qq_41738599的博客 1170

android底部弹窗,Android实现底部弹出Dialog示例(一)

一.概述先给大家看一下效果图:点击中间的显示弹框按钮,从底部弹出来一个对话框,用户可以点击拍照或者从相册选择进行相应的操作,下面看看怎么实现。二.代码实现主页面布局文件,很简单,一个按钮,响应点击事件:xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/t...

weixin_42468901的博客 2870

Android实现底部弹出Dialog(一)

一.概述先给大家看一下效果图:点击中间的显示弹框按钮,从底部弹出来一个对话框,用户可以点击拍照或者从相册选择进行相应的操作,下面看看怎么实现。二.代码实现主页面布局文件,很简单,一个按钮,响应点击事件:<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com

Small_Lee的博客 3万+

Android实现屏幕底部弹出Dialog(附带源码)

Android实现屏幕底部弹出Dialog(附带源码)

欢迎来到我的博客!这里是一个专注于计算机技术的分享平台,涵盖编程开发、算法研究、系统架构、软件工程等多个领域。无论你是初学者还是资深开发者,都能在这里找到有价值的内容。 1810

Android实现底部弹出Dialog(二)

一.概述和Android实现底部弹出Dialog(一)一样,我们先上效果图:点击中间的弹出对话框按钮,从底部弹出Dialog,我们可以选择拍照,选择相片,以及取消按钮二.代码实现主页面布局:<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://s

Small_Lee的博客 2万+

Android 实现屏幕底部弹出Dialog

Android 实现屏幕底部弹出Dialog 封装使用(本文作为开发中记录使用,请轻喷)日常开发中经常用到Dialog实现用户交互界面每次都要重写一个很麻烦(产品经理一言不合就要求弹窗)效果图 这个效果要的算是比较常见的了 package cn.touna.collection.view;import android.app.Dialog; import android.content.Conte

zhao_doubi的博客 2万+

android 底部弹窗失效,Android实现底部弹出Dialog(和PopWindow实现的效果同样)

布局文件:dialog_custom_layout.xmlandroidandroid:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#fff">android:id="@+id/tv_take_photo"an...

weixin_35801437的博客 480

Android实现底部弹出Dialog(和PopWindow实现的效果一样)

上菜,不,上图: 相信上图的效果,大家在android 设备中经常碰到.有时候进行分享操作的时候—–要求从从底部自下而上弹出.上图中的效果既可以通过自定义Dialog实现也可以通过自定义PopWindow来实现.关于popWindow的实现方式,大家可参照本人的另一篇博文Android自定义popWindow教程....

君羊 2万+

安卓开发弹窗activity风格_安卓两种底部弹出dialog实现方式

【实例简介】安卓两种底部弹出dialog实现方式,一种是列表弹窗实现,2是灵活底部弹窗,传入布局以及控件id【实例截图】【核心代码】package com.kx.kxbottomdialog;import android.content.Context;import android.os.Bundle;import android.support.v7.app.AppCompatActivity...

weixin_42298062的博客 1065

Android 控件——利用Dialog实现底部弹出对话框

前言: 实现底部弹框的方式有多种,下面来说说我目前项目中使用到的一种方式效果图如下 使用情景:当用户触发某一事件的时候即可弹出此页面,具体来看看代码是怎么实现的。 (1)在Activity页面中调用如下代码 Dialog mCameraDialog = new Dialog(this, R.style.my_dialog); LinearLayout root

七号座先生的博客 2万+

Android安卓用Dialog对话框简单并且完美实现popupWindow底部弹出效果,有动画效果

1背景 项目中经常用到popupwindow从底部弹出的样式,而且存在有动画,最初实现这种效果用是的popupwindow实现起来十分复杂(指的是动画要实现,效果要好),代码基类书写的代码量大。后来发现对话框可以实现底部弹出效果,实验后发现,代码量奇迹般变少了,特分享一下思路和代码 2看效果 3 要点 主要用到了自定义对话框的进出动画,对话框样式,设置对话框的屏幕宽度和位置等相关的方

u012990509的博客 1196

Android 实现底部弹出Dialog

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

xxb52306的博客 1213

数值分析(浙大版 金一庆)课件

浙江大学版《数值分析》金一庆等编著。第二版的教学课件,适用于本科高年级学生,且有一定高等数学及高等代数基础。PPT格式。

上一篇: Minimum supported Gradle version is 3.3. Current version is 2.14.1
下一篇: HBuilder连接不上逍遥Android模拟器
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值