您的位置:首页 > 其它

倒计时替换

2018-03-25 14:16 106 查看
XMl:
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mmaster.myapplicationb.MainActivity">

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="欢迎来到积云教育"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>


Activity:
public class MainActivity extends AppCompatActivity {

private TextView tv;
private Handler handler = new Handler();
private int i = 0;
private Runnable runnable = new Runnable() {
@Override
public void run() {
tv.setText("我在学Android");
i++;
if (i == 2) {
Intent intent = new Intent(MainActivity.this, ShouYeActivity.class);
startActivity(intent);
finish();
} else {
handler.postDelayed(runnable, 2000);
}
}
};

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}

private void initView() {
tv = (TextView) findViewById(R.id.tv);
handler.postDelayed(runnable, 2000);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: