private boolean isFirstClick (){ SharedPreferences sp = getSharedPreferences ( Constants . GET_EFAX_KEY , Context . MODE_PRIVATE ); //在Constants类中设定一final value,存储,以便一次点击事件后不再显示 boolean firstcli
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来承载图片
<LinearLayoutandroid: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的覆盖问题