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?
The FloatingActionButton from this library extends ImageView which extends View:
It is not a subclass of the Android Button. Cast instead to FloatingActionButton:
FloatingActionButton myButton = (FloatingActionButton) findViewById(R.id.fab);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.