我有一个浮动操作按钮,我打算在片段上显示一个活动。当波纹可见时,FAB不会响应点击。 我搜索了类似的问题,但我发现的答案没有奏效。浮动操作按钮没有响应点击
这是我的FAB布局。
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:theme="@style/MyTheme">
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainActivityFragmentContainer"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/homeFAB"
android:layout_width="65dp"
android:layout_height="65dp"
android:layout_gravity="bottom|center"
android:layout_margin="16dp"
android:src="@drawable/ic_add_image"
android:onClick="runThis"
app:layout_anchor="@id/MainActivityFragmentContainer"
app:layout_anchorGravity="bottom|center" />
我重新排列按钮的顺序在协调布局内的布局,但没有奏效。 然后我将android:onclick="runThis"
添加到XML中的FAB和活动中的方法。
public void runThis(View view) {
Toast.makeText(SlidingMenuActivity.this, "CLICKED", Toast.LENGTH_LONG).show();
}
获得以下错误:
java.lang.IllegalArgumentException: Expected receiver of type xxx.xxx.SlidingMenuActivity, but got android.support.v7.internal.view.ContextThemeWrapper
请帮我找出我错过了什么。 谢谢
尝试view.getContext()代替SlidingMenuActivity.this – poss
@poss好吧,我想试试,让你知道会发生什么 – Zet
相关谷歌代码讨论[这里](https://code.google。 COM/p/android/issues/detail?id = 174871) –