浮动操作按钮不会引发OnClick事件 [英] Floating Action Button does not raise OnClick event
本文介绍了浮动操作按钮不会引发OnClick事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的布局如下:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:id="@+id/rlMap">
<org.mapsforge.map.android.view.MapView
android:id="@+id/mapView"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/windArrow"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_gravity="top|right|end"
android:src="@drawable/arrow"
android:layout_alignStart="@+id/fab" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right|end"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:src="@drawable/settings"
android:clickable="true"/>
</RelativeLayout>
以及OnCreate方法中的以下代码:
And the following code in the OnCreate method:
...
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.d(TAG,"FAB Setting Clicked");
Intent i = new Intent(getApplicationContext(), AppPreferences.class);
startActivity(i);
}
});
...
但是当我按下按钮时,什么也没有发生,意图没有运行,并且日志也没有写入.
But when I press the button nothing happens, The intent does not run, and the log is not written.
按钮动画正在工作,每次我按下按钮时,都会显示以下日志消息:
The button animation is working and every time I press the button the following log message appears :
D/ViewRootImpl:ViewPostImeInputStage ACTION_DOWN
D/ViewRootImpl: ViewPostImeInputStage ACTION_DOWN
所以似乎有些反应.
我在做什么错了?
推荐答案
@Tasos建议的解决方案有效:
The solution suggested by @Tasos worked:
在xml中添加点击事件,例如
add a click event inside the xml e.g
android:onClick="runThis"
,然后在活动"中添加
public void runThis(View v) { ..... }
这篇关于浮动操作按钮不会引发OnClick事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文