first time tips

本文介绍了一种使用SharedPreferences记录首次点击事件的方法,并展示了如何在应用程序启动时仅第一次展示引导图片。通过简单的代码实现,确保用户体验的同时避免重复提示。
private boolean isFirstClick(){
		SharedPreferences sp = getSharedPreferences(Constants.GET_EFAX_KEY, Context.MODE_PRIVATE);
//在Constants类中设定一final value,存储,以便一次点击事件后不再显示
		boolean firstclick = sp.getBoolean(Constants.GET_SHAREDPREF_EFAX_KEY, true);
		return firstclick;
	}
	
	private void setClickFalse(){
		SharedPreferences sp = getSharedPreferences(Constants.GET_EFAX_KEY, Context.MODE_PRIVATE);
		Editor spEditor = sp.edit();
		spEditor.putBoolean(Constants.GET_SHAREDPREF_EFAX_KEY, false);
		spEditor.commit();
	}

 1.在主layout创建一个layout来承载图片

<LinearLayout 
	    android:id="@+id/efax_guide"
	    android:layout_width="match_parent"
	    android:layout_height="match_parent"
	    android:background="@drawable/efax_guide"
	    android:orientation="vertical"
	    android:visibility="gone">  //不占空间不显示
	</LinearLayout>

 

2.在oncreat里面调用该layout

 

mBtn_add_faxPDF = (RadioButton) findViewById(R.id.action_add_fax);
		
        //first time tips
		efaxGuide = (LinearLayout) findViewById(R.id.efax_guide);
		efaxGuide.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				efaxGuide.setVisibility(View.GONE);
		               v.setVisibility(View.GONE);
                              setClickFalse();
				
			}
		});
		
		if (isFirstClick()){
	        Locale locale = getResources().getConfiguration().locale;
	        String language = locale.getLanguage();
	        if (language.endsWith("en")){
	        	efaxGuide.setBackgroundDrawable(getResources().getDrawable(R.drawable.efax_guide));
	        }
	    	efaxGuide.setVisibility(View.VISIBLE);
	    }

 p.s:若first-time-tips不出现,怎可能是布局出现问题,注意不同的parent的覆盖问题

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值