浮动操作按钮不显示 show()?

floating action button doesnt show with show()?

我正在使用 Android 本机 sip 堆栈创建一个简单的 sipcall。我希望在成功的 sip 连接上显示一个特定的浮动操作按钮,并在不成功的 sip 连接上隐藏相同的浮动操作按钮。默认情况下显示浮动操作按钮。一些如何显示部分不起作用并且找不到任何解决方案。正在处理 android 版本 27。以下是 sip 配置文件的实现部分。

                        /**
                         * Name: onRegistrationDone
                         * Description: Logs a status message indicating the
                         *              SipProfile successfully registered.
                         */
                        public void onRegistrationDone(String localProfileUri, long expiryTime) {



                            Log.e("$$", "Sip Profile <" + localProfileUri + "> successfully registered");
                            System.out.println( " login successful");

// 我在成功注册时显示浮动操作按钮 - 不起作用

                        FloatingActionButton fab3 = (FloatingActionButton) findViewById(R.id.fab3);
                        fab3.show();
                        }

                        /**
                         * Name: onRegistrationFailed
                         * Description: Logs a status message indicating the
                         *              SipProfile failed to register.
                         */
                        public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {

// 隐藏浮动操作按钮 - 有效

                            FloatingActionButton fab3 = (FloatingActionButton) findViewById(R.id.fab3);

                            fab3.hide();


                            Log.e("$$", "Sip Profile failed to register <" + localProfileUri + "> " +
                                    " Error message: " + errorMessage);
                            System.out.println( " login unsuccessful. Error message:" + errorMessage);
                        }
                    });
        } catch (ParseException e) {
            Log.e("$$", "SipProfile was not built.");
            e.printStackTrace();
        } catch (SipException e) {
            e.printStackTrace();
        }
    }
}

错误

android.util.AndroidRuntimeException: Animators may only be run on Looper threads
        at android.animation.ValueAnimator.start(ValueAnimator.java:969)
        at android.animation.ValueAnimator.start(ValueAnimator.java:1010)
        at android.animation.AnimatorSet.start(AnimatorSet.java:678)
        at android.animation.AnimatorSet.onChildAnimatorEnded(AnimatorSet.java:807)
        at android.animation.AnimatorSet.start(AnimatorSet.java:640)
        at com.google.android.material.floatingactionbutton.FloatingActionButtonImpl.hide(FloatingActionButtonImpl.java:423)
        at com.google.android.material.floatingactionbutton.FloatingActionButton.hide(FloatingActionButton.java:540)
        at com.google.android.material.floatingactionbutton.FloatingActionButton.hide(FloatingActionButton.java:536)
        at com.google.android.material.floatingactionbutton.FloatingActionButton.hide(FloatingActionButton.java:525)
        at com.serv24.eframe.MediaPresentationActivity.onRegistrationFailed(MediaPresentationActivity.java:1550)
        at android.net.sip.SipManager$ListenerRelay.onRegistrationFailed(SipManager.java:652)
        at android.net.sip.ISipSessionListener$Stub.onTransact(ISipSessionListener.java:180)
        at android.os.Binder.execTransact(Binder.java:573)

请试试这个,它可能会有帮助:

runOnUiThread(new Runnable() {
            @Override
            public void run() {
                fab3.show();
            }
        });