对应的效果图
不需要交任何 依赖
下面 来看看布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.newstablayout.MainActivity">
<Button
android:text="点击"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/button3" />
</LinearLayout>
下面就是 对应的Mainactiviy
public class MainActivity extends AppCompatActivity implements View.OnClickListener{
/* private Intent intent;*/
Button button3;
private TimeCount time;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* findViewById(R.id.button).setOnClickListener(this);
findViewById(R.id.button2).setOnClickListener(this);*/
button3 = (Button)findViewById(R.id.button3);
time = new TimeCount(60000, 1000);
button3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
time.start();
}
});
}
/* @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button:
intent=new Intent(MainActivity.this, TabLessActivity.class);
break;
case R.id.button2:
intent=new Intent(MainActivity.this, TabManyActivity.class);
break;
}
startActivity(intent);
}*/
class TimeCount extends CountDownTimer {
public TimeCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
@Override
public void onTick(long millisUntilFinished) {
button3.setBackgroundColor(Color.parseColor("#B6B6D8"));
button3.setClickable(false);
button3.setText("("+millisUntilFinished / 1000 +") ");
}
@Override
public void onFinish() {
button3.setText("重新获取验证码");
button3.setClickable(true);
button3.setBackgroundColor(Color.parseColor("#4EB84A"));
}
}
}