2

I am new to Android Butterknife and want to change the background color of floating Button. I am unable to do this.How can i achieve this.Thanks in advance.Application crashes when i use .

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

This works fine if i donot integrate Butterknife. This is my floating Button

    <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" />

And in 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();
}
Cœur
  • 37,241
  • 25
  • 195
  • 267
Niroj
  • 1,114
  • 6
  • 29
  • 3
    Possible duplicate of [How to change FAB background color](http://stackoverflow.com/questions/34606766/how-to-change-fab-background-color) – miken32 Aug 23 '16 at 18:16
  • Before using Butterknife setBackgroundTintList had worked fine and when i use Butterknife app suddenly crashes... – Niroj Aug 24 '16 at 01:30

2 Answers2

6

Use app:backgroundTint="@color/your_color"

Satan Pandeya
  • 3,747
  • 4
  • 27
  • 53
2

I have found this answer from @tdamian-kozlakejjd. Follow this link this might help you How to change FAB background color

app:backgroundTint="@color/YOURCOLOR"
xmlns:app="http://schemas.android.com/apk/res-auto" 
Community
  • 1
  • 1
Saugat Bhattarai
  • 2,614
  • 4
  • 24
  • 33