2016-09-27 33 views
0

スナックバーのアクションボタンの背景色を変更する方法、または消えるようにする方法はありますか(灰色の背景)?スナックバーのアクションボタンの背景色を変更します

 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(); 

と私の質問が重複していない:私はこのコードを使用

enter image description here

。私は、テキストの色ではなく背景色を求めています。最初に私たちは読んで、それから私たちは理解し、それから私たちは考えて、誰かの質問が重複していると書くことにしました。

+2

可能な複製([スナックバーアクションテキストの色が変化していない] http://stackoverflow.com/questions/31116774/snackbar-action-text-color-not-changing) –

+0

コードを追加できますか? –

+1

あなたはカスタムスナックバーを作ってみることができます。 http://stackoverflow.com/a/33441214/4344258 –

答えて

1

このコードスニペットはあなたを助けることがあります。

リファレンス Click Hereため
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); 

関連する問題