Hi i have a FAB fab_main that has an onclick that enables other FAB's for onclick. now fab_main's onclick works, but the others are not working at all, why? the code is identical, no?
already tried cancelling the hide() for them but that doesn't help...
I might try switching to the support library fab, but if that was the problem fab_main's onclick wouldn't have worked ether, right?
xml:
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_action_button_main"
style="@style/Widget.MaterialComponents.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:clickable="true"
app:srcCompat="@android:drawable/ic_input_add" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_action_button_house"
style="@style/Widget.MaterialComponents.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:clickable="true"
app:srcCompat="@android:drawable/ic_input_add" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/floating_action_button_building"
style="@style/Widget.MaterialComponents.FloatingActionButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_margin="16dp"
android:clickable="true"
app:srcCompat="@android:drawable/ic_input_add" />
java:
import com.google.android.material.floatingactionbutton.FloatingActionButton;
FloatingActionButton fab_main = findViewById(R.id.floating_action_button_main);
FloatingActionButton fab_house = findViewById(R.id.floating_action_button_house);
FloatingActionButton fab_Building = findViewById(R.id.floating_action_button_building);
//hides fabs
fab_house.hide();
fab_Building.hide();
//defines the main fab onclick
fab_main.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(!isFABOpen){
showFABMenu();
}else{
closeFABMenu();
}
}
});
fab_house.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
closeFABMenu();
});
}
});
}
private void showFABMenu(){
FloatingActionButton fab_main = findViewById(R.id.floating_action_button_main);
FloatingActionButton fab_house = findViewById(R.id.floating_action_button_house);
FloatingActionButton fab_Building = findViewById(R.id.floating_action_button_building);
isFABOpen=true;
fab_house.setOnClickListener(null);
fab_Building.setOnClickListener(null);
fab_house.show();
fab_Building.show();
fab_house.animate().translationY(-getResources().getDimension(R.dimen.standard_62));
fab_Building.animate().translationY(-getResources().getDimension(R.dimen.standard_125));
}
private void closeFABMenu(){
FloatingActionButton fab_main = findViewById(R.id.floating_action_button_main);
FloatingActionButton fab_house = findViewById(R.id.floating_action_button_house);
FloatingActionButton fab_Building = findViewById(R.id.floating_action_button_building);
isFABOpen=false;
fab_house.animate().translationY(0);
fab_Building.animate().translationY(0);
fab_house.hide();
fab_Building.hide();
}
EDIT: My mistake, the fab onclick nulls should have been in the other function...
In your function showFABMenu()
, this line removes the fab_house
's onClickListener()
:
fab_house.setOnClickListener(null);
Remove this line to fix the problem
The fab_Building
has no onClickListener()
defined