I\'m trying to use the new Android P FloatingActionButton that\'s part of the com.google.android.material.floatingactionbutton.FloatingActionButton
and I\'m get
Use:
myButton.hide();
myClearButton.hide();
A typical example would be:
Hiding and showing buttons when user is typing or has focus on a EditText resource:
check if user is typing or has focus:
mCommentField.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
if (hasFocus) {
//user has focused
showBts();
} else {
//focus has stopped perform your desired action
hideButtons();
}
}
});
Hide and Show button methods:
private void hideButtons() {
mCommentButton.hide();
mClearButton.hide();
}
private void showBts() {
mCommentButton. show();
mClearButton.show();
And in your xml, set the buttons to invisible by default so that they only display/show when a user has focus or is typing:
android:visibility="invisible"
Best practice:
android:visibility="Gone"
Using visibility gone means your view is doesn't take up any space on your layout while "invisible" will take up unnecessary space on your layout
In this example:My Views are in a ViewHolder and iam referencing the buttons from a a fragment with a recylerview
This also works:
findViewById(R.id.fab).setVisibility(View.GONE);