Reputation: 2305
I am using this library FAB
: FABToolbar
I want to hide fab button when isShow it, and i want to write this code in onBackPressed()
but this code show me error.
onBackPress method code:
@Override
public void onBackPressed() {
if (fabToolbar.show()) {
fabToolbar.hide();
} else {
onBackPressed();
}
}
but show me this error :
How can i fix this problem and check isShow for this FAB ?
Upvotes: 0
Views: 276
Reputation: 5287
This library is a RelativeLayout
, therefore you can use the public boolean isShown()
method from View
:
To hide the button if it's shown, and then close the activity, do as follow :
@Override
public void onBackPressed() {
if (fabToolbar.isToolbar()) {
fabToolbar.hide();
}
super.onBackPressed();
}
However, if you want your back button to behave as Is Fab showing? If so hide it, otherwise close the activity Then have the following :
@Override
public void onBackPressed() {
if (fabToolbar.isToolbar()) {
fabToolbar.hide();
} else
super.onBackPressed();
}
}
EDIT : N J is correct, the library uses isToolbar()
to store the visibility.
Upvotes: 2
Reputation: 27535
If you look properly in library isToolbar()
isToolbar()
return true if ToolBar is visible else it will return false
public boolean isToolbar() {
return isToolbar;
}
if (fabToolbar.isToolbar()) {
fabToolbar.hide();
} else
super.onBackPressed();
}
Upvotes: 1
Reputation: 73
its must be fabToolbar.isShown() and super.onBackPressed() when you use inside
@Override
public void onBackPressed() {
if (fabToolbar.isShown()) {
fabToolbar.hide();
} else {
super.onBackPressed();
}
}
Upvotes: 0