【问题标题】:Custom view FloatingActionButton has setOnTouchListener called on it but does not override performClick自定义视图 FloatingActionButton 调用了 setOnTouchListener 但不覆盖 performClick
【发布时间】:2017-06-30 00:05:50
【问题描述】:

我对收到的警告感到非常困惑,因为我没有使用自定义类,我只是使用浮动操作按钮。有谁知道如何解决这个问题?

" 自定义视图 FloatingActionButton 调用了 setOnTouchListener 但不会覆盖 performClick "

FloatingActionButton touchFab = (FloatingActionButton) findViewById(R.id.floatingActionButton);
        touchFab.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                switch (event.getAction()) {
                    case MotionEvent.ACTION_DOWN:
                        round.setRound();
                        round.setStartTime(System.currentTimeMillis());
                        return false;
                    case MotionEvent.ACTION_UP:
                        round.setEndTime(System.currentTimeMillis());
//                      setRecordedTime(round.getTimeDiff());
                        round.afterRound();
                        createFragment();
                        return false;
                    default:
                        return false;
                }
            }
        });

FAB 的相关 XML。

<android.support.design.widget.FloatingActionButton
            android:id="@+id/floatingActionButton"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_marginEnd="12dp"
            android:layout_marginLeft="12dp"
            android:layout_marginRight="12dp"
            android:layout_marginStart="12dp"
            android:clickable="true"
            android:focusable="true"
            app:backgroundTint="#FFF"
            app:fabSize="normal"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:rippleColor="@color/colorPrimaryDark"/>

经过一些测试,问题似乎只是Android Studio 3.0 Canary,我刚回到稳定版的Studio,没有错误。如果有人能理解为什么会弹出新版本的警告,那将不胜感激。

【问题讨论】:

    标签: android floating-action-button


    【解决方案1】:

    我也有同样的问题。 我的结果覆盖方法 performClick():

    class FAButton(context: Context?) : FloatingActionButton(context){
        override fun performClick(): Boolean {
            return super.performClick()
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多