Android P visibilityawareimagebutton.setVisibility can only be called from the same library group

前端 未结 8 1831
不思量自难忘°
不思量自难忘° 2020-12-23 20:00

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

相关标签:
8条回答
  • 2020-12-23 20:47

    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

    0 讨论(0)
  • 2020-12-23 20:50

    This also works:

    findViewById(R.id.fab).setVisibility(View.GONE);
    
    0 讨论(0)
提交回复
热议问题