BottomDialog 是一个通过 DialogFragment 实现的底部弹窗布局,并且支持弹出动画,支持任意布局http://shaohui.me

BottomDialog

项目地址: shaohui10086/BottomDialog
简介:BottomDialog 是一个通过 DialogFragment 实现的底部弹窗布局,并且支持弹出动画,支持任意布局 http://shaohui.me

build license

中文版

BottomDialog is a bottom dialog layout implemented with DialogFragment,And supports pop-up animation, support any layout

Preview

BottomDialogShare BottomDialogShare

Import

Maven

<dependency>
  <groupId>me.shaohui</groupId>
  <artifactId>bottomdialog</artifactId>
  <version>1.1.9</version>
  <type>pom</type>
</dependency>

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 layout
                .show();

Of course, you can also make simple settings:

BottomDialog.create(getSupportFragmentManager())
                .setViewListener(new BottomDialog.ViewListener() {    
                    @Override
                    public void bindView(View v) {
                        // // You can do any of the necessary the operation with the view
                    }
                })
                .setLayoutRes(R.layout.dialog_layout)  
                .setDimAmount(0.1f)            // Dialog window dim amount(can change window background color), range:0 to 1,default is : 0.2f
                .setCancelOutside(false)     // click the external area whether is closed, default is : true
                .setTag("BottomDialog")     // setting the DialogFragment tag
                .show();

So Easy!

2.or extends BaseBottomDialog to use

First of all, according to your needs to define a class,extends BaseBottomDialog,For example belowShareBottomDialog

public class ShareBottomDialog extends BaseBottomDialog{

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_layout;
    }

    @Override
    public void bindView(View v) {
        // do any thing you want
    }
}

So simple, only two abstract methods needed to achieve, the rest is to add your logic. Of course, you can also rewrite some of the necessary methods to meet your needs, You can manipulate this Dialog as you would a Fragment

int getHeight()                 // return your bottomDialog height

float getDimAmount()            // set dialog dim amount(can change window background color), default is 0.2f

boolean getCancelOutside()      // click the external area whether is closed, default is : true

String getFragmentTag()         // set dialogFragment tag

The rest is use it:

    ShareBottomDialog dialog = new ShareBottomDialog();
    dialog.show(getFragmentManager());

That is all!

Issue

If you are in the process of using, encountered any problems, welcome to put forward issue

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
实现在全屏中央显示弹窗,可以先设置弹窗的宽度和高度为 `MATCH_PARENT`,然后将弹窗的重心设置为 `CENTER`,这样就可以将弹窗居中显示。具体的代码可以参考以下示例: ``` Dialog dialog = new Dialog(context); dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); dialog.setContentView(R.layout.dialog_layout); Window window = dialog.getWindow(); window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT); window.setGravity(Gravity.CENTER); dialog.show(); ``` 要实现在悬浮窗之下显示弹窗,可以设置弹窗的窗口类型为 `TYPE_SYSTEM_OVERLAY`,这样就可以将弹窗显示在所有应用程序窗口之上,但是仍然位于系统级悬浮窗之下。具体的代码可以参考以下示例: ``` Dialog dialog = new Dialog(context, android.R.style.Theme_Translucent_NoTitleBar); dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY); dialog.setContentView(R.layout.dialog_layout); WindowManager.LayoutParams layoutParams = dialog.getWindow().getAttributes(); layoutParams.width = WindowManager.LayoutParams.WRAP_CONTENT; layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; layoutParams.gravity = Gravity.CENTER; dialog.getWindow().setAttributes(layoutParams); dialog.show(); ``` 要实现在新弹出弹窗之下显示弹窗,可以使用 `DialogFragment` 实现嵌套弹窗。具体的代码可以参考以下示例: ``` public class NestedDialogFragment extends DialogFragment { private static final String TAG = "NestedDialogFragment"; private Dialog mNestedDialog; public static NestedDialogFragment newInstance() { return new NestedDialogFragment(); } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NO_FRAME, android.R.style.Theme_Holo_Light_Dialog_NoActionBar); } @NonNull @Override public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) { mNestedDialog = new Dialog(requireContext(), android.R.style.Theme_Holo_Light_Dialog_NoActionBar); mNestedDialog.setContentView(R.layout.nested_dialog_layout); Window window = mNestedDialog.getWindow(); WindowManager.LayoutParams layoutParams = window.getAttributes(); layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT; layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT; layoutParams.gravity = Gravity.BOTTOM; window.setAttributes(layoutParams); window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE); return mNestedDialog; } @Override public void onStart() { super.onStart(); if (mNestedDialog != null) { mNestedDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT); } } } ``` 在嵌套的 `DialogFragment` 中使用 `Dialog` 显示嵌套的弹窗,然后将嵌套弹窗的重心设置为 `BOTTOM`,这样就可以将嵌套弹窗显示在原来的弹窗之下。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值