我的 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/