Snackbar在第一次弹出时不显示动作

时间:2015-08-20 14:37:52

标签: java android android-5.0-lollipop android-design-library android-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) {

            }
        };

    }

};

1 个答案:

答案 0 :(得分:0)

当您第一次调用函数时,onClickListener为空。

移动:

mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    };

之前if(result.isFailure()),甚至是某种onCreate()。