问题
I know this is a very simple and maybe stupid question but I am having trouble putting an OnClickListener for my Floating Action Button. I have never done one for a button I did not make myself (Using a library) and I just need some help. Here is the code that I am using: https://gist.github.com/VirusThePanda/20320afd303150c02ea5
Here is the library that I am using for the button, and the source code I am using for the navigation bar. This might come in handy as it has a placeholder fragment that may be attached to the main activity.
Source: android-toolbar-with-drawer (From GitHub) Library: android-floating-action-button (From GitHub)
Again, I am sorry for the very simple question. I am still learning Java and XML. Thanks for any help :)
回答1:
Try this :
<com.getbase.floatingactionbutton.FloatingActionsMenu
android:id="@+id/multiple_actions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:onClick="fabClicked"
fab:fab_addButtonColorNormal="#ec407a"
fab:fab_addButtonColorPressed="#d81b60"
fab:fab_labelStyle="@style/menu_labels_style"
android:layout_marginBottom="16dp"
android:layout_marginRight="16dp"
android:layout_marginEnd="16dp"/>
Then, in your activity file (ie. in class custom_motivation), define the function fabClicked as :
...
public void fabClicked(View v){
// write your code here ..
}
...
来源:https://stackoverflow.com/questions/28551322/how-to-set-onclicklistener-android