我想将此视图案例保存到共享首选项中,因此它仅在应用程序运行时首次显示,此处为我的代码:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_contact, menu);
new Handler().postDelayed(
new Runnable() {
@Override
public void run() {
mFancyShowCaseView = new FancyShowCaseView.Builder(ContactTabActivity.this)
.focusOn(findViewById(R.id.item_sync)) // ActionBar menu item id
.focusCircleRadiusFactor(1.5)
.customView(R.layout.case_view_sync, new OnViewInflateListener() {
@Override
public void onViewInflated(@NonNull View view) {
view.findViewById(R.id.btnOke).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mFancyShowCaseView.removeView(); // this doesn't work
}
});
}
}).closeOnTouch(false)
.build();
mFancyShowCaseView .show();
}
}, 50
);
return super.onCreateOptionsMenu(menu);
}
答案 0 :(得分:1)
您无法保存功能,但您可以保存逻辑,这将停止执行功能,如
SharedPreferences pref;
SharedPreferences.Editor editor;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
pref = getSharedPreferences(this,Context.MODE_PRIVATE);
editor = pref.edit();
if(pref.getBoolean("isFirstTime",true){ // default true for first time
editor.putBoolean("isFirstTime",false).commit(); //<-- update so it will false ever after
getMenuInflater().inflate(R.menu.menu_contact, menu);
new Handler().postDelayed(
new Runnable() {
@Override
public void run() {
mFancyShowCaseView = new FancyShowCaseView.Builder(ContactTabActivity.this)
.focusOn(findViewById(R.id.item_sync)) // ActionBar menu item id
.focusCircleRadiusFactor(1.5)
.customView(R.layout.case_view_sync, new OnViewInflateListener() {
@Override
public void onViewInflated(@NonNull View view) {
view.findViewById(R.id.btnOke).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mFancyShowCaseView.removeView(); // this doesn't work
}
});
}
}).closeOnTouch(false)
.build();
mFancyShowCaseView .show();
}
}, 50
);
}
return super.onCreateOptionsMenu(menu);
}