android - Activity 不在 android 4.4 kitkat 上显示 fab 图标

标签 android floating-action-button

我的 Activity 中有一个简单的 fab 图标,它在 android 7.0 中运行良好,但是当我在 android 4.4 上运行我的应用程序时我看不到 fab,我尝试更改 fab 的属性但没有任何效果。

这是我的xml代码

<android.support.design.widget.CoordinatorLayout android:layout_height="match_parent"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">

<android.support.design.widget.FloatingActionButton
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_margin="16dp"
    android:layout_gravity="bottom|end"
    android:id="@+id/fab1"
    app:fabSize="mini"/>

<FrameLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/container"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/srl"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <user.app.CustomWebView
            android:id="@+id/web1"
            android:layout_width="match_parent"
            android:layout_height="match_parent"/>

    </android.support.v4.widget.SwipeRefreshLayout>

</FrameLayout>


</android.support.design.widget.CoordinatorLayout>

这是我的 Activity 。

public class TestActivity extends AppCompatActivity {

FloatingActionButton fab1;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_test);

    fab1 = (FloatingActionButton) findViewById(R.id.fab1);

    fab1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Toast.makeText(TestActivity.this, "you just clicked the fab", Toast.LENGTH_SHORT).show();
        }
    });
}
}

最佳答案

您的 fab 被您的框架布局隐藏了。在 XML 中将晶圆厂放在其下方,使其位于顶部而不是下方。

因为material layout elevation effect在android 7可见

关于android - Activity 不在 android 4.4 kitkat 上显示 fab 图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46267609/

相关文章:

java - 如何将简单按钮锚定到 snackbar

带有 float 操作按钮和 Snackbar 问题的 Android Bottom Sheet

java - float 操作按钮加号未显示

Android 相机 Intent 在某些设备上不起作用

java - 仅当满足以下条件时才执行类中的所有方法

android - 在 android 8 上使用 android 数据绑定(bind)时应用程序崩溃

android - 锚定到应用栏的 FAB 不会在向上滚动时隐藏

Android GPS 跟踪器每次返回 0 的经度和纬度

android - 使用 Retrofit 解析动态 key Json 字符串

react-native - React Native上的 float 操作按钮