有一个这样的需求:当app进入首页的时候,首次显示有一个弹框,弹框中有一个CheckBox按钮,当我们勾选这个按钮后,下次再进来就不再显示弹框,若是没有勾线按钮,每一次进来都要弹出这个弹框,这个需求和以前的app首页进入的时候判断导航页有点类似,只是跳转了不同的导航页界面而已,下面看看代码:
1.调用方法:
date();
2.方法中的逻辑:
private void date() {
SharedPreferences shared= getSharedPreferences("is", MODE_PRIVATE);
boolean isfer=shared.getBoolean("isfer", true);
editor = shared.edit();
if(isfer){
//第一次进入跳转
showWeiXinDialog();
}else{
//第二次
}
}
3.弹框中的逻辑:
private void showWeiXinDialog() {
try {
final Dialog dialog = new Dialog(this, R.style.MyProgressDialogTheme);
dialog.setCancelable(false);
dialog.show();
Window window = dialog.getWindow();
window.setContentView(R.layout.jclq_prompt_dialog);
window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
CheckBox cb_jclq_tishi = (CheckBox) window.findViewById(R.id.cb_jclq_tishi);
cb_jclq_tishi.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean isChecked) {
if(isChecked){
showShortToast("1");
editor.putBoolean("isfer", false);
editor.commit();
}else{
showShortToast("2");
}
}
});
LinearLayout llayout_dialgo_jclq_yes = (LinearLayout) window.findViewById(R.id.llayout_dialgo_jclq_yes);
llayout_dialgo_jclq_yes.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
dialog.dismiss();
}
});
} catch (Exception e) {
e.printStackTrace();
GlobalException.proxy.handle(e);
}
}
4.弹框布局 jclq_prompt_dialog.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<LinearLayout
android:layout_width="290dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:background="@drawable/bg_white_corner"
android:orientation="vertical">
<TextView
android:id="@+id/tv_dialgo_jclq_title"
android:layout_width="match_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="友情提示"
android:textColor="#282828"
android:textSize="16sp" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/line_solid" />
<com.yasenagat.yy.rf.util.CenterTextView
android:id="@+id/ctv_dialog_jclq_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_margin="15dp"
android:gravity="center"
android:text="竞彩篮球盘口变化较快,在传输出票过程中会存在变盘的情况,提交时页面显示的盘口仅供参考,实际算奖金以出票盘口为准。"
android:textColor="#333"
android:textSize="15sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/line_solid">
</View>
<LinearLayout
android:id="@+id/ll_jclq_tishi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<CheckBox
android:id="@+id/cb_jclq_tishi"
style="@style/Default_text_black_l"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:button="@drawable/checkbox_background_login"
android:gravity="center"
android:paddingLeft="5dp"
android:text="不再提示"
android:textColor="@color/gray_9" />
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="@color/line_solid"></View>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:orientation="horizontal">
<!--<LinearLayout-->
<!--android:id="@+id/llayout_dialgo_jclq_no"-->
<!--android:layout_width="0dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_weight="1"-->
<!--android:background="@drawable/bg_white_corner_1"-->
<!--android:orientation="horizontal"-->
<!--android:visibility="visible">-->
<!--<TextView-->
<!--android:id="@+id/tv_no"-->
<!--android:layout_width="0dp"-->
<!--android:layout_height="match_parent"-->
<!--android:layout_weight="1"-->
<!--android:gravity="center"-->
<!--android:text=""-->
<!--android:textColor="@color/receipt_rqgd_color"-->
<!--android:textSize="15sp" />-->
<!--</LinearLayout>-->
<LinearLayout
android:id="@+id/llayout_dialgo_jclq_yes"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@drawable/bg_red_corner_4"
android:orientation="horizontal"
android:visibility="visible">
<TextView
android:id="@+id/tv_yes"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:text="确认"
android:textColor="@color/white"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>