private class gestureListener extendsGestureDetector.SimpleOnGestureListener {public boolean onDown(MotionEvent e) {Log.i("MyGesture", "onDown");if (lutFilterRecyclerView.getVisibility() == View.VISIBLE) {lutFilterRecyclerView.setVisibility(View.GONE);is_filter_on = false;}return false;}public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) {return true;}}
四、实例
①系统弹窗的点击事件.及五种内置样式:
private void showDeleteDialog() {final AlertDialog.Builder builder = new AlertDialog.Builder(this, AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);builder.setTitle(R.string.notice).setMessage(R.string.delete_message).setPositiveButton("Yes", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {MobclickAgent.onEvent(HistoryActivity.this, "main_click_history_clean");mHistoryDatabase.clearHistory();mHistoryAdapter.clear();mHistoryAdapter.notifyDataSetChanged();}}).setNegativeButton("No", new DialogInterface.OnClickListener() {@Overridepublic void onClick(DialogInterface dialog,int which) {return;}});builder.create().show();}
注意导包时选择 .app.;而不是 ..v7.app.;
1)传统主题:默认样式
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_TRADITIONAL)
2)深黑色主题
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_HOLO_DARK);
3)深蓝色主题
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_HOLO_LIGHT);
4)浅黑色主题
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_DEVICE_DEFAULT_DARK);
5) 浅蓝色主题
AlertDialog.Builder builder = new AlertDialog.Builder(DialogActivity.this,AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
![长期更新 Android常用监听事件汇总](http://img.gansulong.com/230810/044154C50-1.png)
文章插图
使用自定义弹窗:
// 第一次进入应用 弹出权限弹窗if(PreferenceManager.getDefaultSharedPreferences(this).getBoolean("show_permission_dialog",true)) {showPermissionDialog();PreferenceManager.getDefaultSharedPreferences(this).edit().putBoolean("show_permission_dialog", false).apply();}// 自定义权限弹窗private void showPermissionDialog() {View view = View.inflate(this, R.layout.dialog_permission, null);TextView mPermission;mPermission = (TextView) view.findViewById(R.id.request_permission);final Dialog dialog = new Dialog(this);dialog.setContentView(view);dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);int divierId = getResources().getIdentifier("android:id/titleDivider", null, null);View divider = dialog.findViewById(divierId);if (divider != null) {divider.setBackgroundColor(Color.TRANSPARENT);}mPermission.setOnClickListener(new View.OnClickListener() {@Overridepublic void onClick(View v) {requestCameraAndStoragePermission();dialog.dismiss();}});try {dialog.show();} catch (Exception e) {e.printStackTrace();}WindowManager.LayoutParams p = dialog.getWindow().getAttributes(); //获取对话框当前的参数值p.width = Math.round(DensityUtil.dip2px(this, 320));p.height = WindowManager.LayoutParams.WRAP_CONTENT;p.gravity = Gravity.CENTER_VERTICAL;/* 默认将弹窗居中,下面将弹窗向上移float w = getResources().getDisplayMetrics().widthPixels * 1.0f;float h = getResources().getDisplayMetrics().heightPixels * 1.0f;mScreenRatio = h / w;if (mScreenRatio > 1.9) {p.y = -Math.round(DensityUtil.dip2px(this, 20));} else {p.y = -Math.round(DensityUtil.dip2px(this, 45));}*/dialog.setCancelable(false); // 点击屏幕空白处 弹窗不消失dialog.setCanceledOnTouchOutside(false); // 点击返回按钮 弹窗不消失dialog.getWindow().setAttributes(p);}
- ios微内核和鸿蒙微内核,华为鸿蒙OS 1.0.1更新
- Android Wear 手机与手表数据通讯
- Android 7.0修改ro属性
- Android开发笔记之简易画画板的制作
- android-沉浸状态栏以及状态栏背景色如何设置
- 如何将android studio设置复位,将设置恢复到初始化
- 小米android10升级版本
- androidGPS驱动
- Android集成支付宝移动支付功能
- ipad太老了,系统无法更新怎么办