效果

XML布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/fill_stroke"
android:theme="@style/SplashTheme"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:paddingTop="15dp"
android:text="温馨提示"
android:textColor="#FF008b8b"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:paddingTop="10dp"
android:paddingBottom="5dp"
android:text="欢迎您使用情义礼簿,根据《个人信息安全规范》的要求,尊重并保护用户个人隐私安全,请您在使用前仔细阅读下方的《用户协议》和《隐私政策》条款,同意后开启我们的服务。"
android:textColor="#5C5C5C"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="5dp">
<TextView
android:id="@+id/YongHu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="用户协议"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF008b8b" />
<View
android:layout_width="30dp"
android:layout_height="match_parent" />
<TextView
android:id="@+id/YinSi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="隐私政策"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FF008b8b" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#eee" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/but_return"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:text="取消"
android:textColor="#999"
android:textSize="16sp" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#eee" />
<TextView
android:id="@+id/but_ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:paddingTop="15dp"
android:paddingBottom="15dp"
android:text="同意"
android:textColor="#FF008b8b"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
Activity核心代码
public void isFirstStart() {
SharedPreferences preferences = getSharedPreferences("NB_FIRST_START", 0);
boolean isFirst = preferences.getBoolean("FIRST_START", true);
if (isFirst) {// 第一次
AlertDialog.Builder builder = new AlertDialog.Builder(this);
//获取界面
View view = LayoutInflater.from(this).inflate(R.layout.dialog_privacy_show, null);
//将界面填充到AlertDiaLog容器并去除边框
builder.setView(view);
//取消点击外部消失弹窗
builder.setCancelable(false);
//创建AlertDiaLog
builder.create();
//AlertDiaLog显示
AlertDialog dialog = builder.show();
// 移除dialog的decorview背景色
dialog.getWindow().getDecorView().setBackground(null);
//初始化控件
TextView but_ok = view.findViewById(R.id.but_ok);
TextView but_return = view.findViewById(R.id.but_return);
TextView YongHu = view.findViewById(R.id.YongHu);
YongHu.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
YongHu.getPaint().setAntiAlias(true);//抗锯齿
TextView YinSi = view.findViewById(R.id.YinSi);
YinSi.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);//下划线
YinSi.getPaint().setAntiAlias(true);//抗锯齿
//同意按钮
but_ok.setOnClickListener(view1 -> {
preferences.edit().putBoolean("FIRST_START", false).apply();
dialog.dismiss();
startActivity(new Intent(SplashActivity.this, MainActivity.class));
//finish();
//倒计时执行
//handler.sendEmptyMessageDelayed(0, 1000);
});
//取消按钮
but_return.setOnClickListener(view1 -> {
dialog.dismiss();
finish();
});
//用户协议
YongHu.setOnClickListener(view1 -> {
//startActivity(new Intent(this, ProtocolActivity.class));
Intent intent = new Intent(SplashActivity.this, ProtocolActivity.class);
Bundle bundle=new Bundle();
bundle.putInt("type", 2);
intent.putExtras(bundle);
startActivity(intent);
});
//隐私政策
YinSi.setOnClickListener(view1 -> {
//startActivity(new Intent(this, ProtocolActivity.class));
Intent intent = new Intent(SplashActivity.this, ProtocolActivity.class);
Bundle bundle=new Bundle();
bundle.putInt("type", 1);
intent.putExtras(bundle);
startActivity(intent);
});
} else {
preferences.edit().putBoolean("FIRST_START", false).apply();
//Handler handler = new Handler();
//handler.postDelayed(() -> {
//startActivity(new Intent(SplashActivity.this, MainActivity.class));
//finish();
//}, 2000);
handler.sendEmptyMessageDelayed(0, 1000);
}
}