Put the address on GitHub first, welcome star, also welcome to send me issues

LDialog

A library based on DialogFragment encapsulation recommended by Google, extraction and encapsulation according to their own business, this library is all written with Kotlin, Java can also be invoked, can meet most of the project needs, can be used in activities and fragments. This project guideline is to observe the maximum degree of freedom.

This database has the following features:

  • Horizontal and portrait rotation saves the state of Dialog properties (and maintains the state of DialogFragment events, such as click events)
  • Fully custom interface
  • Rich interface property Settings
  • Perfect keyboard eject (not using delay)

Suggestion: DialogFragment has many advantages over AlertDialog. However, the simpler AlertDialog is recommended for situations where very simple information prompts are required, only native styles are required, and horizontal and portrait screens are not considered. Please do not complicate simple issues. DialogFragment can be used when there are UI requirements and usage requirements.

If you have not started koltin, it is recommended to learn to use. The environment version of this library is as follows:

  • Kotlin 1.2.51
  • Android support 27.1.1

preview

Unable to record vertical/horizontal switchover due to screen recording restrictions. Download the Demo experience

Demo Download Address

demo apk

To obtain

This library is divided into LDialog must be imported and CustomLDialog is not required. LDialog as the base library; The CustomLDialog contains custom styles that are not required to be imported. In Build. gradle’s Repositories add:

allprojects {
	repositories{... maven { url'https://jitpack.io'}}}Copy the code

In Dependencies, add:

dependencies {
	// Must import
	implementation 'com. Making. Limuyang2. LDialog: LDialog: 1.0'
	//3 custom styles, do not use do not import
	implementation 'com. Making. Limuyang2. LDialog: custom_ldialog: 1.0'
}
Copy the code

Simple to use

LDialog and CustonLDialog inherit from BaseLDialog class.

Init (), supportFragmentManager for the Activity, childFragmentManager for the Fragment

How CustonLDialog is used

Currently there are 3 custom styles:

  • IOSMsgDialog
  • MaterialMsgDialog
  • BottomTextListDialog

The following takes the MaterialMsgDialog as an example:

//koltin
MaterialMsgDialog.init(supportFragmentManager) // Use childFragmentManager in Freagment
	.setTitle("Material Style")
	.setMessage("This is Material Design dialog!")
	.setNegativeButton("Decline", View.OnClickListener {
		Toast.makeText(this@MainActivity."Decline", Toast.LENGTH_SHORT).show()
    })
    .setPositiveButton("Accept", View.OnClickListener {
        Toast.makeText(this@MainActivity."Accept", Toast.LENGTH_SHORT).show()
    })
    .show()
Copy the code
//java
MaterialMsgDialog.Companion.init(getSupportFragmentManager())
	.setTitle("Material Style")
	.setMessage("This is Material Design dialog!")
	.setNegativeButton("Decline".new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			Toast.makeText(JavaDemo.this."Decline", Toast.LENGTH_SHORT).show()
        }
    })
    .setPositiveButton("Accept".new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(JavaDemo.this."Accept", Toast.LENGTH_SHORT).show()
        }
    })
    .show();
Copy the code

LDialog Usage mode (main usage mode)

Customize the layout using layoutRes. The following is an example:

//kotlin
LDialog.init(supportFragmentManager)
	.setLayoutRes(R.layout.ldialog_share)
	.setBackgroundDrawableRes(R.drawable.shape_share_dialog_bg)
	.setGravity(Gravity.BOTTOM)
	.setWidthScale(0.95f)
	.setVerticalMargin(0.015f)
	.setAnimStyle(R.style.LDialogBottomAnimation)
	.setViewHandlerListener(object : ViewHandlerListener() {
		override fun convertView(holder: ViewHolder, dialog: BaseLDialog< * >) {
        	holder.setOnClickListener(R.id.cancelBtn, View.OnClickListener {
            	dialog.dismiss()
            })
       }
    })
    .show()
Copy the code

For details about how to use Java, see javademo.java under the project

Method statement

The method name instructions
setLayoutRes Set layout resources [priority above setLayoutView] [LDialog only, must]
setLayoutView Set layout view (not recommended)
* setViewHandlerListener (Important) Sets the properties of the control in the layout. If horizontal and portrait rotation is [needed] to be considered, the relevant properties of the control must be set here. It is recommended that all Settings for the controls in the layout be written here. 【 LDialog only, must 】
General method (BaseLDialog)
setBackgroundDrawableRes Id of the popover background resource file
setTag The label DialogFragment
setDismissListener Popover of close monitor
setGravity Form position (example: Gravity.CENTER Gravity.TOP)
setWidthScale Proportion of screen width (range 0.0-1.0, 1.0 is overspread) [priority above setWidthDp]
setWidthDp The width of Dialog, in dp
setHeightScale Proportion of screen height (range 0.0-1.0) [Priority over setHeightDp]
setHeightDp The height of Dialog, in dp
setKeepWidthScale (default: false) whether to keep the setWidthScale in landscape mode (only valid if setWidthScale is set)
setKeepHeightScale (Default: false) Whether to keep the height scale set when landscape screen is displayed (this will only take effect if setHeightScale is set)
setVerticalMargin Set Margin (0.0-0.1) for vertical direction
setCancelableAll Sets whether the dialog can be closed by clicking outside dialog and the return key
setCancelableOutside Set whether to close dialog by clicking outside dialog (return key unaffected)
setAnimStyle Animation Style resource file ID
setNeedKeyboardEditTextId Sets the id of the control that needs to automatically pop up the keyboard. The control must be of type EditText
show Display Dialog

Use advanced

If that still doesn’t meet your needs, you can directly inherit from the BaseLDialog class and have the generic method. Refer to the three popover classes in CustonLDialog for details. The basic writing is as follows:

class ExKotlinLdialog : BaseLDialog<ExKotlinLdialog>() {

    override fun layoutRes(a): Int = R.layout.ldialog_share

    override fun layoutView(a): View? = null

    /** * Must * If horizontal and portrait rotation is [needed] to be considered, the control properties are set here *@return* /
    override fun viewHandler(a): ViewHandlerListener? {
        return object : ViewHandlerListener() {
            override fun convertView(holder: ViewHolder, dialog: BaseLDialog< * >){}}}/** * Optional * If horizontal and portrait rotation is not considered, the control properties can also be set here *@param view
     */
    override fun initView(view: View){}}Copy the code

For Java usage, see exJavalDialog.java under the project

License

2018 limuyang
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except inThe 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 toin 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.
Copy the code