我想在FloatingActionButton上顯示文字而不是圖標。因此,我使用FrameLayout來實現這一點。但是,沒有任何onClickListerners正在工作。我已經設置android:clickable="true"
仍然沒有改變。 下面是我的樣本佈局文件:FloatingActionButton在framelayout裏面不起作用
<FrameLayout
android:id="@+id/frame"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="bottom|end"
android:clickable="true"
android:layout_margin="@dimen/activity_horizontal_margin">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<TextView
android:id="@+id/text"
android:layout_width="30dp"
android:layout_height="match_parent"
android:elevation="7dp"
android:gravity="center"
android:layout_gravity="center_horizontal"
android:maxLines="3"
android:text="My Text"
android:clickable="true"
android:textAllCaps="true"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@android:color/white"
android:textSize="8sp"
android:textStyle="bold" />
</FrameLayout>
我嘗試使用這兩種方法: 1.在所有三個要素設置android:onClick="myMethod"
2.設置onClickListener編程,即FrameLayout裏,FAB和TextView的Activity類裏面
但是,我通常使用FAB,即不使用FrameLayout;它工作正常。
請提供一些解決方案。
編輯:Activity.java
fab = (FloatingActionButton) findViewById(R.id.fab);
text= (TextView) findViewById(R.id.text);
frame = (FrameLayout) findViewById(R.id.frame);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myMethod();
}
});
text.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myMethod();
}
});
frame.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
myMethod();
}
});
本內myMethod的記錄器()實現。看來onClick事件沒有被觸發,因爲我在控制檯中看不到任何日誌。
更新:: 佈局文件還包含與FrameLayout相同級別的RecyclerView。問題是否由於RecyclerView的存在而發生?
從framelayout中刪除'android:clickable =「true」'.. – rafsanahmad007
請發佈您的點擊事件代碼 – Shivam
使用浮動按鈕很重要嗎?因爲..你可以通過設置圓形背景按鈕來達到同樣的效果。 –