2016-09-27 162 views
0

如何更改小吃店中操作按鈕的背景顏色或使其消失(灰色背景)?更改小吃店中操作按鈕的背景顏色

enter image description here

我用這個代碼:

 Snackbar mysnack = Snackbar.make(main_layout, getResources().getString(R.string.snack_1), 5000); 
      View view = mysnack.getView(); 
      TextView tv = (TextView) view.findViewById(android.support.design.R.id.snackbar_text); 
      tv.setTextColor(getResources().getColor(R.color.text_light)); 
      mysnack.setActionTextColor(getResources().getColor(R.color.text_light)); 
      mysnack.setAction("RATE", new View.OnClickListener() { 
       @Override 
       public void onClick(View view) { 
        Uri uri = Uri.parse(getResources().getString(R.string.snack_url)); 
        Intent intent = new Intent(Intent.ACTION_VIEW, uri); 
        startActivity(intent); 
       } 
      }); 
      TypedValue typedValue = new TypedValue(); 
      getTheme().resolveAttribute(R.attr.colorPrimaryDark, typedValue, true); 
      final int color = typedValue.data; 
      mysnack.getView().setBackgroundColor(color); 
      mysnack.show(); 

和我的問題是不重複的。我要求背景顏色而不是文字顏色。首先我們閱讀,然後我們理解,然後我們思考,然後我們決定寫一個人的問題是重複的。

+2

的可能的複製[小吃吧行動文字顏色不改變(http://stackoverflow.com/questions/31116774/snackbar-action-text-color-not-change) –

+0

你可以添加代碼嗎? –

+1

你可以嘗試製作一個自定義小吃吧。 http://stackoverflow.com/a/33441214/4344258 –

回答

1

這段代碼可以幫助你:

Snackbar snackbar = Snackbar.make(
        coordinatorLayout, 
        "Snackbar: floatingActionButton1 (normal) clicked", 
        Snackbar.LENGTH_LONG); 
      snackbar.setActionTextColor(Color.RED); 
      View snackbarView = snackbar.getView(); 
      snackbarView.setBackgroundColor(Color.WHITE); 
      TextView textView = (TextView) snackbarView.findViewById(android.support.design.R.id.snackbar_text); 
      textView.setTextColor(Color.BLUE); 

借鑑Click Here