简体   繁体   English

Fab按钮android onClick崩溃了应用程序?

[英]Fab button android onClick is crashing the app?

The (Floating action button) works but when I try to set it as a button it crashes the app? (浮动操作按钮)有效,但是当我尝试将其设置为按钮时会导致应用程序崩溃?

Button MyButton = (Button) findViewById(R.id.fab);
MyButton.setOnClickListener(new View.OnClickListener() {
  public void onClick(View v) {
    // Perform action on click
  }
});

The above crashes the app, but when I remove it everything is fine? 上面的代码使应用程序崩溃,但是当我将其删除时,一切正常吗? Any ideas? 有任何想法吗?

https://github.com/makovkastar/FloatingActionButton https://github.com/makovkastar/FloatingActionButton

The FloatingActionButton from this library extends ImageView which extends View: 该库中的FloatingActionButton扩展了ImageView,后者扩展了View:

https://github.com/makovkastar/FloatingActionButton/blob/master/library/src/main/java/com/melnykov/fab/FloatingActionButton.java https://github.com/makovkastar/FloatingActionButton/blob/master/library/src/main/java/com/melnykov/fab/FloatingActionButton.java

It is not a subclass of the Android Button. 它不是Android Button的子类。 Cast instead to FloatingActionButton: 改为投放到FloatingActionButton:

FloatingActionButton myButton = (FloatingActionButton) findViewById(R.id.fab);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM