android - float 操作按钮未出现在 kitkat 中

标签 android xml android-5.0-lollipop android-4.4-kitkat floating-action-button

我创建了一个单页应用程序,其中 float 操作按钮用于共享页面中的内容。它在 android lollipop 中完美运行,但是当我在 kitkat 上运行该应用程序时,它没有显示。由于唯一的交互组件是 FAB,用户除了盯着看别无他法。我进行了一些搜索,发现 FAB 应该在 kitkat 上完美运行,并且只有在涉及 Lollipop (如填充)时才会出现一些问题。但是,它在 Lollipop 中工作得很好。对于早于 lollipop 的版本,我是否必须将其更改为按钮?我的第一个问题在这里。任何帮助表示赞赏。谢谢。

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="com.ataraxianstudios.decksharer.MainActivity"
    >


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@drawable/share1"/>

<ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#016cb4">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:id="@+id/llMain"
        >
<Spinner
        android:id="@+id/osversions"
        android:layout_width="220dp"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        />
    <ImageView
        android:layout_width="60dp"
        android:layout_height="80dp"
        android:id="@+id/selectedImage"
        />

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

最佳答案

我也有同样的问题,可能是由于 Material 设计,因为 Material 设计是在 kitkat 之后引入的,所以在某些选项卡或布局上存在一些问题,但试试这个它对我有用,也许对你有用..

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout     
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="com.ataraxianstudios.decksharer.MainActivity"
>



//Replace your fab from here

<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#016cb4">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:id="@+id/llMain"
    >
<Spinner
    android:id="@+id/osversions"
    android:layout_width="220dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    />
<ImageView
    android:layout_width="60dp"
    android:layout_height="80dp"
    android:id="@+id/selectedImage"
    />

</LinearLayout>
</ScrollView>


//to here:
<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@drawable/share1"/>
</android.support.design.widget.CoordinatorLayout>

关于android - float 操作按钮未出现在 kitkat 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36883148/

相关文章:

android - android 转换到打瞌睡模式需要多长时间?

c# - 使用 XSD.exe 从多个 XSD 模式生成 c# 类

android - 从 ICS ActionBar 切换到 Lollipop 工具栏后缺少导航图标

android - 如何使用 Android Lollipop 中的注释在 Android Jackson 解析期间修复 IncompatibleClassChangeError?

Android:控制返回到启动画面

android - RecyclerView notifyItemRemoved(位置)无法正常工作

android - 进度条错误

java - jbpm6-build.xml :508: jboss did not start within 5 minutes

python - 使用 ET 删除 Python 中的元素

android - 带有 Spannable 的按钮 setText 不适用于 Android 5.0 Lollipop