2017-08-28 2 views
0

アクティビティがフラグメントからイベントを受け取ると、アクティビティはスナックバーを作成し、スナックバーのバックグラウンドを変更する必要があります。SnackBar BackgroundColor EventBus例外の変更

8月28日16:15:58.233 13491から13491 E/EventBus: しかし、ログにそのエラーを行う際には、次のように発生したクラスのクラスHomeActivityに アンドロイドをサブスクライブするクラスSearchPickingListEvent:イベントを送出しませんでした。 content.res.Resources $ NotFoundException:

@Subscribe(threadMode = ThreadMode.MAIN) 
    public void onSearchListEvent(SearchListEvent searchListEvent) { 
     if (searchListEvent.isSuccess()) { 
      loadingEventsUI(getString(R.string.findingPickingList), Snackbar.LENGTH_INDEFINITE, 
        ContextCompat.getColor(this, R.color.snackbar_background_warning)); 

        controller.fetchInvoice(searchListEvent.getCdCode(), 
        searchListEvent.getPickingListNumber()); 
     } else { 
      showMessage(R.string.orderinvalid); 
     } 
    } 



private void loadingEventsUI(String message, int duration, int color){ 
     mSmoothProgressBar.progressiveStart(); 
     mSmoothProgressBar.setVisibility(View.VISIBLE); 
     mSnackbar = Snackbar.make(btnMainMenu, message, duration); 
     mSnackbar.getView().setBackgroundColor(ContextCompat.getColor(this, color)); 
     mSnackbar.show(); 
    } 

エロライン:リソースID番号0xffffce00

フラグメントイベントを受け取る方法は、このようなものですmSnackbar.getView().setBackgroundColor(ContextCompat.getColor(this, color));

答えて

1

あなたが二回ContextCompat.getColor()を呼び出しているように見えます:

public void onSearchListEvent(SearchListEvent searchListEvent) { 
    ... 
    loadingEventsUI([message], [duration], ContextCompat.getColor(this, R.color.snackbar_background_warning)); 
    ... 
} 

private void loadingEventsUI(String message, int duration, int color){ 
    ... 
    mSnackbar.getView().setBackgroundColor(ContextCompat.getColor(this, color)); 
    ... 
} 

を単に直接colorを使用するsetBackgroundColor()への呼び出しを変更します。