如何设置OnClickListener(Android) [英] How To Set OnClickListener (Android)
问题描述
我知道这是一个非常简单甚至愚蠢的问题,但是我在为浮动操作按钮"放置OnClickListener时遇到了麻烦.我从来没有做过一个我自己没有做过的按钮(使用图书馆),我只需要一些帮助.这是我正在使用的代码: https://gist.github.com/VirusThePanda/20320afd303150c02ea5
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.
来源:android-toolbar-with-drawer(来自GitHub) 库:android-floating-action-button(来自GitHub)
Source: android-toolbar-with-drawer (From GitHub) Library: android-floating-action-button (From GitHub)
同样,对于非常简单的问题,我感到抱歉.我仍在学习Java和XML.感谢您的帮助:)
Again, I am sorry for the very simple question. I am still learning Java and XML. Thanks for any help :)
推荐答案
尝试一下:
<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"/>
然后,在您的活动文件中(即在custom_motivation类中),将fabClicked函数定义为:
Then, in your activity file (ie. in class custom_motivation), define the function fabClicked as :
...
public void fabClicked(View v){
// write your code here ..
}
...
这篇关于如何设置OnClickListener(Android)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!