zoukankan      html  css  js  c++  java
  • Android 滑块验证

    先上图看看实现效果

    1.在 app 的 build.gradle 添加依赖

    implementation 'com.luozm.captcha:captcha:1.1.2'
    

    2.将 Captcha 添加至布局文件

     <com.luozm.captcha.Captcha
            android:id="@+id/captCha"
            android:layout_centerInParent="true"
            android:layout_width="match_parent"
            android:layout_height="265dp"
            android:layout_marginRight="10dp"
            android:layout_marginLeft="10dp"
            app:mode="mode_bar"
            app:src="@drawable/validate"
            app:blockSize="50dp"
            android:scaleType="centerCrop"
            app:max_fail_count="4"/>
    

    3.添加 Java 代码

        public void showw(String advPic) {
    
            Context context = MainActivity.this;
            diaa = new Dialog(context, R.style.edit_AlertDialog_style);
            diaa.setContentView(R.layout.item_pict);
    
            captcha = diaa.findViewById(R.id.captCha);
            final Button btn_mode = diaa.findViewById(R.id.btn_mode);
            final Captcha captcha = diaa.findViewById(R.id.captCha);
            ImageView cuowu = diaa.findViewById(R.id.im_cuowu);
            // Glide.with(getApplication()).load(advPic).into(captcha );
            captcha.setBitmap(advPic);
    
            btn_mode.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (captcha.getMode() == Captcha.MODE_BAR) {
                        captcha.setMode(Captcha.MODE_NONBAR);
                        btn_mode.setText("滑动条模式");
                    } else {
                        captcha.setMode(Captcha.MODE_BAR);
                        btn_mode.setText("无滑动条模式");
                    }
                }
            });
    
            cuowu.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    diaa.dismiss();
                    itData(mLongitude, mLatitude);
                }
            });
    
            captcha.setCaptchaListener(new Captcha.CaptchaListener() {
                @Override
                public String onAccess(long time) {
                    Toast.makeText(MainActivity.this, "验证成功", Toast.LENGTH_SHORT).show();
    
    
                    diaa.dismiss();
                    diaa.setCanceledOnTouchOutside(true);
                    return "验证通过";
    
                }
    
                @Override
                public String onFailed(int count) {
                    Toast.makeText(MainActivity.this, "验证失败,失败次数" + count, Toast.LENGTH_SHORT).show();
                    return "验证失败";
                }
    
                @Override
                public String onMaxFailed() {
                    Toast.makeText(MainActivity.this, "验证超过次数,你的帐号被封锁", Toast.LENGTH_SHORT).show();
                    return "可以走了";
                }
    
            });
    
            diaa.show();
    
            diaa.setCanceledOnTouchOutside(true);
    
    
            Window w = diaa.getWindow();
            WindowManager.LayoutParams lp = w.getAttributes();
            lp.x = 0;
            lp.y = 40;
            diaa.onWindowAttributesChanged(lp);
     
        }
    
     
  • 相关阅读:
    Python与常见加密方式
    ERROR 2002 (HY000):Can't connect to local MySQL server though socket '/var/lib/mysql/mysql.sock'(2)
    hive的分区表
    内部表和外部表的区别
    hive之SQL
    执行wc的时候提示连接被拒绝。Connection refused
    hive的简介
    hive的部署
    top命令信息
    web界面解读
  • 原文地址:https://www.cnblogs.com/monkey0928/p/9864094.html
Copyright © 2011-2022 走看看