我有一個浮動操作按鈕,我打算在片段上顯示一個活動。當波紋可見時,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) –