gpt4 book ai didi

java - FloatingActionButton OnClickListener 不适用于 API 17

转载 作者:太空宇宙 更新时间:2023-11-03 11:42:44 25 4
gpt4 key购买 nike

我的 FAB onClick 在 API 17 上不工作,但在 API 21 上工作正常。

我正在使用:

compile 'com.android.support:design:23.+'

FAB 布局:

<android.support.design.widget.FloatingActionButton
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom"
android:layout_marginBottom="26dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:backgroundTint="#FFC107"
android:clickable="true"
android:elevation="@dimen/design_fab_elevation"
android:src="@drawable/ic_add_24dp"
app:borderWidth="0dp" />

关于 Activity :

myFAB = (FloatingActionButton) findViewById(R.id.myFAB);
callCadastroEncoemnda();

protected void callCadastroEncoemnda() {
myFAB.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, newPackage.class);
MainActivity.this.startActivity(intent);
}
});
}

最佳答案

已解决!

在我的布局中,FloatingActionButton 在 RecyclerView 下方,当我点击 Fab 时,我点击的是 RecyclerView(它是空的)

之前:

    <android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<android.support.design.widget.FloatingActionButton
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom"
android:layout_marginBottom="26dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:backgroundTint="#FFC107"
android:clickable="true"
android:elevation="@dimen/design_fab_elevation"
android:src="@drawable/ic_add_24dp"
app:borderWidth="0dp"
android:layout_alignParentTop="false"
android:layout_alignParentRight="false"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentLeft="false" />

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/my_awesome_toolbar">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/my_awesome_toolbar"
android:layout_marginTop="?attr/actionBarSize" />
</android.support.v4.widget.SwipeRefreshLayout>

之后:

    <RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.Toolbar
android:id="@+id/my_awesome_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/primary"
android:elevation="4dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipeRefreshLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/my_awesome_toolbar">

<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/my_awesome_toolbar"
android:layout_marginTop="?attr/actionBarSize" />
</android.support.v4.widget.SwipeRefreshLayout>

<android.support.design.widget.FloatingActionButton
android:id="@+id/myFAB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_gravity="bottom"
android:layout_marginBottom="26dp"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:backgroundTint="#FFC107"
android:clickable="true"
android:elevation="@dimen/design_fab_elevation"
android:src="@drawable/ic_add_24dp"
app:borderWidth="0dp"
android:layout_alignParentTop="false"
android:layout_alignParentRight="false"
android:layout_alignWithParentIfMissing="false"
android:layout_alignParentLeft="false" />
</RelativeLayout>

关于java - FloatingActionButton OnClickListener 不适用于 API 17,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33673522/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com