Android P visibilityawareimagebutton.setVisibility can only be called from the same library group
Using Method 1
demoFab.show(); // in place of visible
demoFab.hide(); // in place of Invisible suppress the warning/error for me.
and Method 2
@SuppressLint("RestrictedApi") // also suppressed the warning
private void setUp() {
....
}
update:
Method 3:
demoFab.setVisibility(View.GONE);
demoFab.setVisibility(View.INVISIBLE);
demoFab.setVisibility(View.VISIBLE);
Method 4:
demoFab.visibility = View.GONE
demoFab.visibility = View.INVISIBLE
demoFab.visibility = View.VISIBLE
Seems to work fine just to cast it to a view.
(mFloatingActionButton as View).visibility = INVISIBLE
Of course you need to remember that the visibility may affect other components, so you should probably use show()
and hide()
at the same time to make sure other components are notified of the change.
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