2016-08-23 2 views
2

私はAndroid Butterknifeが新しく、浮動ボタンの背景色を変更したいと考えています。私はこれをすることができません。私はこれを達成することができます。事前に感謝します。私が使用すると、アプリケーションがクラッシュします。浮動小数点バックグラウンド(ButterKnife)をプログラム的に変更する

floatingActionButton.setBackgroundTintList(ColorStateList.valueOf(Color 
      .parseColor("#33691E"))); 

Butterknifeを統合しないとうまくいきます。 これは私がtdamian-kozlakejjd @からこの答えを見つけた私の浮動ボタン

<android.support.design.widget.FloatingActionButton 
    android:layout_width="wrap_content" 
    android:id="@+id/fab1" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|right" 
    app:rippleColor="@android:color/white" 
    android:layout_margin="16dp" 
    android:src="@drawable/circle" 
    android:onClick="newForm" 
    app:layout_anchorGravity="bottom|right|end" /> 

そしてMainActivity

public class MainActivity extends AppCompatActivity implements  
SearchView.OnQueryTextListener { 

@BindView(R.id.fab1) 
FloatingActionButton floatingActionButton; 

@BindColor(R.color.colorFolatingButton) 
int Floating_Button_Color; 
@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main); 
    ButterKnife.bind(this); 

    setSupportActionBar(toolbar); 

    floatingActionButton.setBackgroundColor(Floating_Button_Color); 

} 
@OnClick(R.id.fab1) 
public void newForm (View view){ 

    AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); 
    builder.setTitle("Confirm"); 
    builder.setMessage("Are you sure?"); 

    builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      Intent intent = new Intent(getApplicationContext(),BuilderPage.class); 
      startActivity(intent); 
     } 
    }); 


    builder.setNegativeButton("No", new DialogInterface.OnClickListener() { 
     @Override 
     public void onClick(DialogInterface dialog, int which) { 
      dialog.dismiss(); 
     } 
    }); 

    AlertDialog alert = builder.create(); 
    alert.show(); 
} 
+3

[FAB背景色を変更する方法]の可能な重複(http://stackoverflow.com/questions/34606766/how-to-change-fab-background-color ) – miken32

+0

バターナイフを使う前にsetBackgroundTintListは正常に動作していました。バターナイフアプリを突然使用するとクラッシュします... – Niroj

答えて

6

使用app:backgroundTint="@color/your_color"

+1

私はそれをプログラム的に変更しようとしています。しかしこれもうまくいった。ありがとうございました。 – Niroj

2

です。このリンクに従ってください、これはあなたを助けるかもしれない How to change FAB background color

app:backgroundTint="@color/YOURCOLOR" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
+1

新しい質問には、質問間の回答をコピーするのではなく、クロージャとして重複としてフラグを立てる必要があります。 – miken32

+0

これは次回からは起こりません。私は新しく積み重ねました。 –

関連する問題