To-use version Popupwindow by Kotlin look

Outline

XPopupWindow, PopupWindow system for packaging and further strengthening for use. Adopt Kotlin language and offers many additional features such as setting method popups position, adjust the pop animation and so on.

project address

XPopupWindow

Preview

XPopupWindow-demo

characteristic

  • Quickly and easily create a custom pop
  • In a relatively convenient location provided pop
  • More freedom to adjust your pop animation

Start

Use Gradle:

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

dependencies {
    implementation 'com.github.XuDeveloper:XPopupWindow:1.0.1'
}

use

To create a login pop as an example:

Write interface

(Slightly containing an account input box, enter a password and login button box, github have demo)

Creating XPopupWindow

/**
 * Created by Xu on 2018/6/17.
 * @author Xu
 */

class InputPopupWindow : XPopupWindow {
    private var btnLogin: Button? = null
    private var etPhone: TextInputEditText? = null

    constructor(ctx: Context) : super(ctx)

    constructor(ctx: Context, w: Int, h: Int) : super(ctx, w, h)

    /**
     * 设置popupwindow的layoutId
     */
    override fun getLayoutId(): Int {
        return R.layout.popup_input
    }

    /**
     * 设置layout的parentNodeId
     */
    override fun getLayoutParentNodeId(): Int {
        return R.id.input_parent
    }

    /**
     * 初始化界面
     */
    override fun initViews() {
        btnLogin = findViewById(R.id.btn_login)
        btnLogin?.setOnClickListener { dismiss() }
        etPhone = findViewById(R.id.et_mobile)
    }

    /**
     * 初始化数据
     */
    override fun initData() {
        // 设置弹窗背景透明度
        setShowingBackgroundAlpha(0.4f)
        // 弹窗弹出时自动获取输入框的焦点
        setAutoShowInput(etPhone, true)
    }

    /**
     * 为弹窗设置弹出动画,如果不想设置或是想通过xml方式设置,则设置返回值为-1
     */
    override fun startAnim(view: View): Animator? {
        var animatorX: ObjectAnimator = ObjectAnimator.ofFloat(view, "scaleX", 0f, 1f)
        var animatorY: ObjectAnimator = ObjectAnimator.ofFloat(view, "scaleY", 0f, 1f)
        var set = AnimatorSet()
        set.play(animatorX).with(animatorY)
        set.duration = 500
        return set
    }

    /**
     * 为弹窗设置退出动画,如果不想设置或是想通过xml方式设置,则设置返回值为-1
     */
    override fun exitAnim(view: View): Animator? {
        var animatorX: ObjectAnimator = ObjectAnimator.ofFloat(view, "scaleX", 1f, 0f)
        var animatorY: ObjectAnimator = ObjectAnimator.ofFloat(view, "scaleY", 1f, 0f)
        var set = AnimatorSet()
        set.play(animatorX).with(animatorY)
        set.duration = 700
        return set
    }

    /**
     * 通过xml方式设置动画,xml编写方法与原生popupwindow设置动画方法相同
     */
    override fun animStyle(): Int {
        return -1
    }

}

Specific use

private fun showInputPopup() {
    inputPopupWindow = InputPopupWindow(this, 1000, 600)
    // 可设置弹窗退出的监听器,在回调中执行相应操作
    inputPopupWindow?.setXPopupDismissListener(object : XPopupWindowDismissListener {
        override fun xPopupBeforeDismiss() {
        }

        override fun xPopupAfterDismiss() {
            Snackbar.make(findViewById(android.R.id.content), "登录成功!", Snackbar.LENGTH_LONG).show()
        }
    })
    inputPopupWindow?.showPopupFromScreenCenter(R.layout.activity_main)
}
  • You can view xpopupwindowdemo to get more use!

To buy me a cup of tea with lemon chant: smile:

Micro letter Alipay

protocol

Copyright [2018] XuDeveloper

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Published 14 original articles · won praise 3 · Views 7544

Guess you like

Origin blog.csdn.net/Xu_1215/article/details/81585367