本文整理了Java中android.app.Dialog.setOnKeyListener()
方法的一些代码示例,展示了Dialog.setOnKeyListener()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Dialog.setOnKeyListener()
方法的具体详情如下:
包路径:android.app.Dialog
类名称:Dialog
方法名:setOnKeyListener
暂无
代码示例来源:origin: gzu-liyujiang/AndroidPicker
public void setOnKeyListener(final DialogInterface.OnKeyListener onKeyListener) {
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
BasicPopup.this.onKey(dialog, keyCode, event);
return onKeyListener.onKey(dialog, keyCode, event);
}
});
LogUtils.verbose(this, "popup setOnKeyListener");
}
代码示例来源:origin: Hitomis/transferee
private void createDialog() {
transDialog = new AlertDialog.Builder(context, getDialogStyle())
.setView(transLayout)
.create();
transDialog.setOnShowListener(this);
transDialog.setOnKeyListener(this);
}
代码示例来源:origin: igreenwood/SimpleCropView
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// タッチしても消えないように設定
dialog.setCancelable(false);
// ビュー全体のリスナ
dialog.setCanceledOnTouchOutside(false);
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
// Disable Back key and Search key
switch (keyCode) {
case KeyEvent.KEYCODE_BACK:
case KeyEvent.KEYCODE_SEARCH:
return true;
default:
return false;
}
}
});
return dialog;
}
}
代码示例来源:origin: gzu-liyujiang/AndroidPicker
private void initDialog() {
contentLayout = new FrameLayout(activity);
contentLayout.setLayoutParams(new ViewGroup.LayoutParams(WRAP_CONTENT, WRAP_CONTENT));
contentLayout.setFocusable(true);
contentLayout.setFocusableInTouchMode(true);
dialog = new Dialog(activity);
dialog.setCanceledOnTouchOutside(true);//触摸屏幕取消窗体
dialog.setCancelable(true);//按返回键取消窗体
dialog.setOnKeyListener(this);
dialog.setOnDismissListener(this);
Window window = dialog.getWindow();
if (window != null) {
window.setGravity(Gravity.BOTTOM);
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
//AndroidRuntimeException: requestFeature() must be called before adding content
window.requestFeature(Window.FEATURE_NO_TITLE);
window.setContentView(contentLayout);
}
setSize(screenWidthPixels, WRAP_CONTENT);
}
代码示例来源:origin: WVector/AppUpdate
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
代码示例来源:origin: zaaach/CityPicker
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
dialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
if (mOnPickListener != null){
mOnPickListener.onCancel();
}
}
return false;
}
});
measure();
Window window = dialog.getWindow();
if (window != null) {
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
window.setGravity(Gravity.BOTTOM);
window.setLayout(width, height - ScreenUtil.getStatusBarHeight(getActivity()));
if (enableAnim) {
window.setWindowAnimations(mAnimStyle);
}
}
}
代码示例来源:origin: Alex-Cin/Dialog
/**
* 设置 物理按键的 监听事件
*
* @param simpleOnKeyListener
*/
public D setOnKeyListener(SimpleOnKeyListener simpleOnKeyListener) {
super.setOnKeyListener(simpleOnKeyListener);
return (D) this;
}
代码示例来源:origin: luoshihai/XXDialog
public XXDialog setOnKeyListener(DialogInterface.OnKeyListener onKeyListener){
mDialog.setOnKeyListener(onKeyListener);
return this;
}
/**
代码示例来源:origin: yanjiabin/ExtendDialog
public ExtendsDialog setOnKeyListener(DialogInterface.OnKeyListener onKeyListener){
mDialog.setOnKeyListener(onKeyListener);
return this;
}
/**
代码示例来源:origin: KosyanMedia/Aviasales-Android-SDK
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.destination_progress_dialog, container);
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (getActivity() != null) {
getActivity().onBackPressed();
return true;
}
}
return false;
}
});
return view;
}
代码示例来源:origin: KosyanMedia/Aviasales-Android-SDK
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
ViewGroup layout = (ViewGroup) inflater.inflate(R.layout.browser_dialog, container, false);
((TextView) layout.findViewById(R.id.tv_loading_agency)).setText(getAgencyText());
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialogInterface, int i, KeyEvent keyEvent) {
if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK) {
if (getActivity() != null) {
getActivity().onBackPressed();
return true;
}
}
return false;
}
});
return layout;
}
代码示例来源:origin: wufenglincheng/ImageTrans
public void show() {
build.checkParam();
mDialog = new AlertDialog.Builder(mContext, getDialogStyle())
.setView(createView())
.create();
build.dialog = mDialog;
mDialog.setOnShowListener(this);
mDialog.setOnKeyListener(this);
mDialog.show();
}
代码示例来源:origin: xbmc/Kore
@Override
public void onResume() {
super.onResume();
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(android.content.DialogInterface dialog, int keyCode,
android.view.KeyEvent event) {
boolean handled = handleVolumeKeyEvent(getContext(), event);
if (handled) {
delayedDismissDialog();
}
return handled;
}
});
}
代码示例来源:origin: lime-ime/limeime
@Override
public void onResume() {
super.onResume();
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(android.content.DialogInterface dialog,
int keyCode, android.view.KeyEvent event) {
if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) {
// To dismiss the fragment when the back-button is pressed.
dismiss();
return true;
}
// Otherwise, do nothing else
else return false;
}
});
}
代码示例来源:origin: lime-ime/limeime
@Override
public void onResume() {
super.onResume();
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(android.content.DialogInterface dialog,
int keyCode, android.view.KeyEvent event) {
if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) {
// To dismiss the fragment when the back-button is pressed.
dismiss();
return true;
}
// Otherwise, do nothing else
else return false;
}
});
}
代码示例来源:origin: lime-ime/limeime
@Override
public void onResume() {
super.onResume();
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(android.content.DialogInterface dialog,
int keyCode, android.view.KeyEvent event) {
if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) {
// To dismiss the fragment when the back-button is pressed.
dismiss();
return true;
}
// Otherwise, do nothing else
else return false;
}
});
}
代码示例来源:origin: lime-ime/limeime
@Override
public void onResume() {
super.onResume();
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(android.content.DialogInterface dialog,
int keyCode, android.view.KeyEvent event) {
if ((keyCode == android.view.KeyEvent.KEYCODE_BACK)) {
// To dismiss the fragment when the back-button is pressed.
dismiss();
return true;
}
// Otherwise, do nothing else
else return false;
}
});
}
代码示例来源:origin: jenly1314/MVPFrame
protected void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio,final boolean isCancel){
dismissDialog();
mDialog = new Dialog(context,resId);
mDialog.setContentView(contentView);
mDialog.setCanceledOnTouchOutside(false);
mDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK && isCancel){
dismissDialog();
}
return true;
}
});
setDialogWindow(mDialog,widthRatio);
mDialog.show();
}
代码示例来源:origin: jenly1314/MVPFrame
protected void showDialog(Context context, View contentView, @StyleRes int resId, float widthRatio,final boolean isCancel){
dismissDialog();
mDialog = new Dialog(context,resId);
mDialog.setContentView(contentView);
mDialog.setCanceledOnTouchOutside(false);
mDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK && isCancel){
dismissDialog();
}
return true;
}
});
setDialogWindow(mDialog,widthRatio);
mDialog.show();
}
代码示例来源:origin: listenzz/AndroidNavigation
protected void setupDialog() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
setStatusBarTranslucent(true);
} else {
setStatusBarTranslucent(presentableActivity.isStatusBarTranslucent());
}
Window window = getWindow();
window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
getDialog().setOnKeyListener(new DialogInterface.OnKeyListener() {
@Override
public boolean onKey(DialogInterface dialogInterface, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
if (!dispatchBackPressed() && isCancelable()) {
dismissDialog();
}
return true;
}
return false;
}
});
}
内容来源于网络,如有侵权,请联系作者删除!