首页 > 解决方案 > Floating action Button visibility issue?

问题描述

In the below code i am trying to make fab button visible during a sip call and invisible when the call is ended.some how fab7.show doesnt show anything, only fab8.hide() works inside oncallended function. Any help would be highly appreciated.

In the below code, when the Fab button was touched for more than 3 second(inside onTouchListener) , i am calling sendingcall function and at the same time make fab8 visible.

when the call is ended , by default below function oncallend function is called , in that function i am hiding fab8.

  fab.setOnTouchListener(new View.OnTouchListener() {
            @Override


            public boolean onTouch(View v, MotionEvent event) {
                call.setListener(myListener);

                switch(event.getAction()){
                    case MotionEvent.ACTION_DOWN:
                        down = System.currentTimeMillis();
                        break;
                    case MotionEvent.ACTION_UP:
                        //this is the time in milliseconds
                        re= System.currentTimeMillis();
                        differ = System.currentTimeMillis()- down;

                        if(differ>=3000){
                            sendingCall();

                            FloatingActionButton fab8 = (FloatingActionButton) findViewById(R.id.fab8);
                             fab8.show();

                        }
                        break;

                }

onCallEnded function is called everytime when the call is ended. And here i am hiding fab button

  public void onCallEnded(SipAudioCall endedCall) {


       FloatingActionButton fab8 = (FloatingActionButton) findViewById(R.id.fab8);
        fab8.hide();  //***only hide works **
     FloatingActionButton fab7 = (FloatingActionButton)  findViewById(R.id.fab7);
     fab7.show();       //.  ******does not shows********
                    Log.d("call", "Call ended.................................");


}

标签: javaandroid-layoutfloating-action-button

解决方案


因此,从对我来说,您在 onTouch 事件中使用 .setVisibility() 并在 onCallEnded 方法中使用 hide() 函数。因此,不要使用 .hide 尝试使用 setVisibility() 再次隐藏按钮。


推荐阅读