Android implementations get CAPTCHA effects

Source: Internet
Author: User

The function is very simple is to define a Countdowntimer directly look at the code

First, put a button code in the XML as follows:


<relativelayout xmlns:android= "http://schemas.android.com/apk/res/android"    xmlns:tools= "http// Schemas.android.com/tools "    android:layout_width=" match_parent "    android:layout_height=" Match_parent "    tools:context= ". Mainactivity ">    <button        android:id=" @+id/btn_getcode "        android:background=" #4DB74A "        Android:layout_width= "Wrap_content"        android:layout_height= "wrap_content"        android:layout_ Alignparentleft= "true"        android:layout_alignparentright= "true"        android:layout_centervertical= "true"        android:text= "point I get Verification code"/></relativelayout>
Here's the main code:

Package Com.example.countdowntimer;import Android.os.bundle;import Android.os.countdowntimer;import Android.app.activity;import Android.graphics.color;import Android.view.menu;import Android.view.View;import Android.view.view.onclicklistener;import Android.widget.button;public class Mainactivity extends Activity {private Timecount time;private Button btngetcode; @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate ( Savedinstancestate); Setcontentview (r.layout.activity_main); time = new Timecount (60000, +); btngetcode= (Button) Findviewbyid (R.id.btn_getcode); Btngetcode.setonclicklistener (new Onclicklistener () {@Overridepublic void OnClick ( View v) {Time.start ();}});} Class Timecount extends Countdowntimer {public Timecount (long millisinfuture, long Countdowninterval) {super ( Millisinfuture, countdowninterval);} @Overridepublic void OnTick (Long millisuntilfinished) {Btngetcode.setbackgroundcolor (Color.parsecolor ("#B6B6D8")); Btngetcode.setclickable (false); Btngetcode.settexT (millisuntilfinished/1000 + seconds to resend);} @Overridepublic void OnFinish () {Btngetcode.settext ("Regain Verification Code"); Btngetcode.setclickable (true); Btngetcode.setbackgroundcolor (Color.parsecolor ("#4EB84A"));}}}
SOURCE Download:



Android implementations get CAPTCHA effects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.