我试图在用户首次运行代码时使用 FadingTextView 显示某些消息。尽管当我第一次运行后再次运行它时,似乎无法使 FadingTextView 停止或显示其他内容。用户第一次打开应用程序后,有什么方法可以阻止这种情况。使用 else {fadingTextView.stop}; 在打开应用程序时将其崩溃。请帮忙!这是我的代码。
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
boolean firstStart = prefs.getBoolean("fistStart", true);
if (firstStart) {
firstTime();
}
}
private void firstTime(){
final TextView wordTextView = findViewById(R.id.wordTextView);
final EditText firstTimeEditText = findViewById(R.id.firstTimeEditText);
arrowImageView = findViewById(R.id.arrowImageView);
fadingTextView = findViewById(R.id.fadingTextView);
fadingTextView.setTimeout(4000, FadingTextView.MILLISECONDS);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
firstTimeEditText.setVisibility(View.VISIBLE);
}
},11950);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
fadingTextView.animate().alpha(0f).setDuration(1000);
firstTimeEditText.animate().alpha(1f).setDuration(1000);
wordTextView.animate().alpha(1f).setDuration(1000);
arrowImageView.animate().alpha(1f).setDuration(1000);
}
},12000);
SharedPreferences prefs = getSharedPreferences("prefs", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean("fistStart",false);
editor.apply();
}