私は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();
}
[FAB背景色を変更する方法]の可能な重複(http://stackoverflow.com/questions/34606766/how-to-change-fab-background-color ) – miken32
バターナイフを使う前にsetBackgroundTintListは正常に動作していました。バターナイフアプリを突然使用するとクラッシュします... – Niroj