常见的小技术

大家好,我叫菜钧:

这是我的第一篇博客。也不知道写什么,就放写常用的东西。方便我自己用到,大家也是。

下面是Dialog的例子:

  private void showAddDialog() {
        final AlertDialog.Builder builer=new AlertDialog.Builder(this);
        builer.setMessage("请添加一个私有云设备");
        builer.setCancelable(false);
        builer.setPositiveButton("确定", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
           builer.create().dismiss();
            }
        });
        builer.create().show();
    }


这里是Popupwindow:

    private PopupWindow mSortWindow;


 private void showSearch(){


        if(null==mSearchWindow){
            View layout = getActivity().getLayoutInflater().inflate(R.layout.layout_search, null);
            mSearchKey= (EditText) layout.findViewById(R.id.et_search);
            layout.findViewById(R.id.btn_search).setOnClickListener(this);
            mSearchWindow= new PopupWindow(layout,200,ViewGroup.LayoutParams.WRAP_CONTENT);
            //配置外部点击以及主动焦点
            mSearchWindow.setFocusable(true);
            mSearchWindow.setOutsideTouchable(true);
            //设置背景以响应返回键
            mSearchWindow.setBackgroundDrawable(new ColorDrawable());


        }
        mSearchWindow.showAsDropDown(mImageViewfile_search);
    }

邮箱验证

case R.id.send_code:
                if (TextUtils.isEmpty(userEmailNumber.getText().toString())) {
                    ToastUtils.showToast(context, "请输入邮箱号码");
                    return;
                } else {
                    //邮箱正则表达式
                    String check = "^[a-z0-9]+([._\\\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$";
                    Pattern pattern = Pattern.compile(check);//表达式
                    Matcher matcher = pattern.matcher(userEmailNumber.getText().toString());
                    boolean isLegal = matcher.matches();
                    if (!isLegal) {
                        Toast.makeText(this, "邮箱格式不正确", Toast.LENGTH_LONG).show();
                        return;
                    }
                }
                sendCode();
                break;

广播的注册等

接收
 public class MyReceiver extends BroadcastReceiver {
        @Override
        public void onReceive (Context context, Intent intent) {
            Bundle bundle = intent.getExtras();
            String fileName = bundle.getString("fileName");//File%getdir*#*
           
            try {
                fileThread = new FileThread(fileName);
                fileThread.start();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }






注册
   //注册广播接收器
        receiver = new MyReceiver();
        IntentFilter filter = new IntentFilter();
        filter.addAction("com.ljq.activity.CountServiceInfo");
        this.registerReceiver(receiver, filter);




发送


  //发送广播
    Intent intent = new Intent();
    intent.putExtra("fileName", "1"+"¥"+path);
    intent.setAction("com.ljq.activity.CountServiceInfo");
    sendBroadcast(intent);
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值