我希望我的启动画面仅在首次启动时显示。我知道我必须通过共享偏好,但如何?这是我的想法:
public class Splash extends Activity {
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
setContentView(R.layout.splash);
//animation
ImageView imageView = (ImageView) findViewById(R.id.imageView);
Animation alpha = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.fade_in);
imageView.startAnimation(alpha);
alpha.setAnimationListener((new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation animation) {
// TODO Start your activity here.
Intent mainIntent = new Intent(Splash.this, MainActivity.class);
Splash.this.startActivity(mainIntent);
Splash.this.finish();
}
}));
}
}
答案 0 :(得分:1)
试试这个:
SharedPreferences mPrefs;
final boolean mLoginSession;
public static final String PREFER_NAME = "MyPrefsFile";
//Inside onCreate
mPrefs = getSharedPreferences(PREFER_NAME, MODE_PRIVATE);
mLoginSession = mPrefs.getBoolean(PREFER_NAME, false);
if (mLoginSession) {
Intent gotoMain = new Intent(Splash.this, MainActivity.class);
startActivity(gotoMain);
finish();
} else {
//Show Splash Data here and Change the shared value of "PREFER_NAME"
SharedPreferences.Editor editor = mPrefs.edit();
editor.putBoolean(PREFER_NAME, true);
editor.commit();
}
答案 1 :(得分:0)
请尝试这样做。
<button (click)="toggle(1)" class="someclass">
<button (click)="toggle(2)" class="someclass">