正如标题所说。我在我的应用程序中实现了 Snackbar 功能,第一次弹出 Snackbar 时它不显示操作,但在第二次它会显示。代码如下。
IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
@Override
public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
if (result.isFailure()) {
if (result.getResponse() == IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
mIsPremium = true;
mAdView.setVisibility(View.GONE);
removebutton.setText("PURCHASED");
Snackbar.make(findViewById(R.id.container2), "Purchased", Snackbar.LENGTH_LONG)
.setAction("UNDO", mOnClickListener)
.setActionTextColor(Color.parseColor("#FFAB40"))
.setDuration(4000).show();
}
} else if (purchase.getSku().equals(ITEM_SKU)) {
mIsPremium = true;
mAdView.setVisibility(View.GONE);
removebutton.setText("PURCHASED");
Snackbar.make(findViewById(R.id.container2), "Ads have been removed", Snackbar.LENGTH_LONG)
.setAction("UNDO", mOnClickListener)
.setActionTextColor(Color.parseColor("#FFAB40"))
.setDuration(4000)
.show();
}
mOnClickListener = new View.OnClickListener() {
@Override
public void onClick(View v) {
}
};
}
};