Advanced dialog solution for android
Simple and advanced dialog solution.
implementation 'com.orhanobut:dialogplus:1.11@aar'
Use the builder to create the dialog.
Basic usage
DialogPlus dialog = DialogPlus.newDialog(this)
.setAdapter(adapter)
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
}
})
.setExpanded(true) // This will enable the expand feature, (similar to android L share dialog)
.create();
dialog.show();
Enable expand animation same as Android L share dialog
.setExpanded(true) // default is false, only works for grid and list
Set expand animation default height
.setExpanded(true, 300)
Select different holder.
setContentHolder(new ListHolder())
or pass view itself
.setContentHolder(new ViewHolder(R.layout.content))
.setContentHolder(new ViewHolder(view))
.setContentHolder(new GridHolder(COLUMN_NUMBER))
View view = dialogPlus.getHolderView();
.setGravity(Gravity.CENTER)
.setCancelable(true)
.setAdapter(adapter);
.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(DialogPlus dialog, Object item, View view, int position) {
}
})
Set a global click listener to you dialog in order to handle all the possible click events. You can then identify the view by using its id and handle the correct behaviour. Only views which has id will trigger this event.
.setOnClickListener(new OnClickListener() {
@Override
public void onClick(DialogPlus dialog, View view) {
}
})
.setMargin(left, top, right, bottom)
.setPadding(left, top, right, bottom)
or use view
.setFooter(R.layout.footer)
.setFooter(view)
View view = dialogPlus.getFooterView();
or use view
.setHeader(R.layout.header)
.setHeader(view)
View view = dialogPlus.getHeaderView();
.setInAnimation(R.anim.abc_fade_in)
.setOutAnimation(R.anim.abc_fade_out)
Set width and height for the content
.setContentWidth(ViewGroup.LayoutParams.WRAP_CONTENT) // or any custom width ie: 300
.setContentHeight(ViewGroup.LayoutParams.WRAP_CONTENT)
Dismiss Listener, triggered when the dialog is dismissed
.setOnDismissListener(new OnDismissListener() {
@Override
public void onDismiss(DialogPlus dialog) {
}
})
Cancel Listener, triggered when the dialog is cancelled by back button or clicking outside
.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogPlus dialog) {
}
})
BackPress Listener, triggered when the back button is pressed
.setOnBackPressListener(new OnBackPressListener() {
@Override
public void onBackPressed(DialogPlus dialog) {
}
})
Change content container background, as default white
.setContentBackgroundResource(resource)
Change overlay container background, as default it’s semi-transparent black
.setOverlayBackgroundResource(resource)
- Copyright 2016 Orhan Obut
- 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.