(suppor Android X)
A library based on Google's recommended DialogFragment package, according to its own business extraction package, the library is written using kotlin, java can also be called, can meet most project needs, can Used in Activity and Fragment. The guiding principle of this project is to adhere to the maximum degree of freedom.
The library currently has the following features:
- Rotate the vertical and vertical screens to save the Dialog property state (and maintain the event state of the DialogFragment, such as a click event)
- Complete custom interface
- Rich interface property settings
- Perfect keyboard automatically pops up (not using delay method)
Recommendations: DialogFragment has many advantages over AlertDialog. However, for simple information prompts, only native styles, and no horizontal and vertical rotation is required, a simpler AlertDialog is recommended. Please don't complicate the simple question.
Source description:
If you haven't gotten started with koltin, it is recommended to learn to use it. The environment version of this library is as follows:
- kotlin 1.3.61
- AndroidX
Due to the limitations of the screen. Please download the demo experience
This library is divided into the necessary LDialog`` and non-essential CustomLDialog. LDialogis the base library;CustomLDialog``` contains custom styles, and you don't need to import them if you don't need them.
First add in the repositories of build.gradle :
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}Add in dependencies:
dependencies {
//Must be imported
implementation 'com.github.limuyang2.LDialog:ldialog:1.0.2'
//3 custom styles, you don't need to import them if you don't need them
implementation 'com.github.limuyang2.LDialog:custom_ldialog:1.0.2'
}if you use Android X,Please use the following:
dependencies {
//Must be imported
implementation 'com.github.limuyang2.LDialog:ldialog:1.0.2_androidx'
//3 custom styles, you don't need to import them if you don't need them
implementation 'com.github.limuyang2.LDialog:custom_ldialog:1.0.2_androidx'
}Both LDialog and CustonLDialog inherit from the BaseLDialog class.
The parameters in init(),
ActivityusesupportFragmentManager,FragmentusingchildFragmentManager
There are currently 3 custom styles:
- IOSMsgDialog
- MaterialMsgDialog
- BottomTextListDialog
The following is an example of MaterialMsgDialog:
//koltin
MaterialMsgDialog.init(supportFragmentManager) //Freagment using childFragmentManager
.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()//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();Used to provide a custom layout using layoutRes.
Examples:
//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()For Java usage, please refer to JavaDemo.java under the project.
If the above still can not meet your needs, you can directly inherit the BaseLDialog class, and also have a general method. For details, please refer to the three Dialog classes in ```CustonLDialog``.
The basic writing is as follows:
class ExKotlinLdialog : BaseLDialog<ExKotlinLdialog>() {
override fun layoutRes(): Int = R.layout.ldialog_share
override fun layoutView(): View? = null
/**
* Must
* If [need] to consider horizontal and vertical rotation, the relevant properties of the control are set here.
* @return
*/
override fun viewHandler(): ViewHandlerListener? {
return object : ViewHandlerListener() {
override fun convertView(holder: ViewHolder, dialog: BaseLDialog<*>) {
}
}
}
/**
* Optional
* If you don't consider the horizontal and vertical rotation, you can also set the control properties here.
* @param view
*/
override fun initView(view: View) {
}
}Java use please refer to ExJavaLdialog.java under the project
If you are using ProGuard you might need to add the following option:
-keep class top.limuyang2.ldialog.base.** { *; }
2018 limuyang
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.

