Coder Social home page Coder Social logo

android_nicedialog's Introduction

NiceDialog

简介:

示例预览:

基本用法:

Step 1. 添加JitPack仓库 在当前项目等根目录下的 build.gradle 文件中添加如下内容:

allprojects {
    repositories {
        ...
        maven { url "https://jitpack.io" }
    }
}

Step 2. 添加项目依赖

dependencies {
        compile 'com.github.Othershe:NiceDialog:1.1.4'
}

Step 3. 配置、展示dialog

NiceDialog.init()
          .setLayoutId(R.layout.dialog)     //设置dialog布局文件
          .setConvertListener(new ViewConvertListener() {     //进行相关View操作的回调
              @Override
              public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {

              }
          })
          .setDimAmount(0.3f)     //调节灰色背景透明度[0-1],默认0.5f
          .setShowBottom(true)     //是否在底部显示dialog,默认flase
          .setMargin()     //dialog左右两边到屏幕边缘的距离(单位:dp),默认0dp
          .setWidth()     //dialog宽度(单位:dp),默认为屏幕宽度,-1代表WRAP_CONTENT
          .setHeight()     //dialog高度(单位:dp),默认为WRAP_CONTENT
          .setOutCancel(false)     //点击dialog外是否可取消,默认true
          .setAnimStyle(R.style.EnterExitAnimation)     //设置dialog进入、退出的动画style(底部显示的dialog有默认动画)
          .show(getSupportFragmentManager());     //显示dialog

注意: setMargin()setWidth()选择一个即可

更多用法:

1、创建一个继承BaseNiceDialog的类,如果需要传参可仿照如下方式,也是就是常用的Fragment传参方式
public class ConfirmDialog extends BaseNiceDialog {
        private String type;

        public static ConfirmDialog newInstance(String type) {
            Bundle bundle = new Bundle();
            bundle.putString("type", type);
            ConfirmDialog dialog = new ConfirmDialog();
            dialog.setArguments(bundle);
            return dialog;
        }

        @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            Bundle bundle = getArguments();
            type = bundle.getString("type");
        }

        @Override
        public int intLayoutId() {
            return R.layout.dialog;
        }

        @Override
        public void convertView(ViewHolder holder, final BaseNiceDialog dialog) {

        }
    }
2、展示dialog
ConfirmDialog.newInstance("1")
             .setMargin(60)
             .setOutCancel(false)
             .show(getSupportFragmentManager());

android_nicedialog's People

Watchers

James Cloos avatar C++ avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.