基本上,我有一个启动屏幕,后面是一个启动活动,底部有一个按钮,还有一个复选框,以避免再次显示所述活动。我怎样才能实现它,这样它就能完成我想做的事情?我是一个自学的新开发人员。我不需要直截了当的回答,只要指出正确的方向。
<CheckBox
android:id="@+id/do_not_show_again"
android:layout_width="249dp"
android:layout_height="21dp"
android:layout_marginTop="12dp"
android:text="@string/do_not_show_again"
android:textAlignment="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.513"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/get_started_button" />
</androidx.constraintlayout.widget.ConstraintLayout>发布于 2019-09-24 19:34:15
不要使用Splash活动。延迟用户3或4秒是没有用的。相反,使用一个完整的视图片段,这将有助于加载主活动的UI元素。将布尔值存储在共享的prefs中,以便永久消失片段。
发布于 2019-09-25 03:06:00
首先,您需要将复选框值存储在共享首选项上。
SharedPreferences sharedpref = getSharedPreferences("shared_prefs", MODE_PRIVATE);
SharedPreferences.Editor sharedpref_editor = sharedpref.edit();;确认复选框是否通过onClick选中,然后在标签“跳过”上存储布尔值真。
YOUR_BUTTON.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (YOUR_CHECKBOX.isChecked()) {
sharedpref_editor.putBoolean("skip", true);
sharedpref_editor.apply();
}
}
});然后,下次您打开该活动时,您的程序应该通过对您的onCreate活动执行此操作,在标签"skip“下检查共享首选项中的值。
Boolean saveSkip = sharedpref.getBoolean("skip", false);
if(saveSkip){
Intent skipIntent = new Intent(MainActivity.this, YourTargetActivity.class);
startActivity(skipIntent);
finish();
}https://stackoverflow.com/questions/58085712
复制相似问题