【问题标题】:Floating action Button visibility issue?浮动操作按钮可见性问题?
【发布时间】:2020-02-26 17:24:59
【问题描述】:

在下面的代码中,我试图让 fab 按钮在 sip 通话期间可见,而在通话结束时不可见。有些 fab7.show 不显示任何内容,只有 fab8.hide() 在 oncallended 函数中起作用。任何帮助将不胜感激。

在下面的代码中,当 Fab 按钮被触摸超过 3 秒(在 onTouchListener 内) ,我正在调用 sendcall 函数,同时制作 fab8 可见。

通话结束时,默认在函数oncallend函数下面 被调用,在那个函数中我隐藏了 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 函数在每次通话结束时被调用。我在这里隐藏了 fab 按钮

  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.................................");


}

【问题讨论】:

  • 您可以简单地使用fab8.setVisiblity(View.GONE) 或fab8.setVisiblity(View.INVISIBLE)
  • 不,它们已被弃用@bhuvneshpattnaik。使用 fab8.show()
  • 嗨@Shine 谢谢它解决了我的一半问题。但是 onCallEnded 函数中的一些 fab7show() 没有显示,只有隐藏部分有效。任何帮助将不胜感激

标签: java android-layout floating-action-button


【解决方案1】:

所以从我这里的样子来看,您在 onTouch 事件中使用 .setVisibility() 并在 onCallEnded 方法中使用 hide() 函数。 所以不要使用 .hide 尝试使用 setVisibility() 再次隐藏按钮。

【讨论】:

  • 反之更好,因为 .setVisibility() 是受保护的方法
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-01-14
  • 1970-01-01
  • 2020-01-02
  • 1970-01-01
  • 2014-10-18
  • 1970-01-01
  • 2012-06-15
相关资源
最近更新 更多