首页 > 解决方案 > Floating Action Button is translucent for some reason

问题描述

I have two Floating Action Buttons in my layout, but for some reason, the two buttons are semi-transparent.

enter image description here

I was wondering how to make the buttons solid? Here's the source code for the layout file:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:orientation="vertical">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/add_assignment_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|end"
            android:src="@drawable/ic_add_white_24dp"
            app:useCompatPadding="true" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/start_session_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="top|end"
            android:src="@drawable/ic_play_arrow_white_24dp"
            app:layout_anchor="@id/add_assignment_button"
            app:layout_anchorGravity="top"
            app:useCompatPadding="true"></android.support.design.widget.FloatingActionButton>
    </LinearLayout>


    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

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

标签: androidandroid-layout

解决方案


浮动操作按钮由于某种原因是半透明的

移动您的FloatingActionButton外部线性布局也无需使用LinearLayout

使您的布局如下所示

示例代码

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">


    <ListView
        android:id="@+id/android:list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1">

    </ListView>


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/add_assignment_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="20dp"
        android:src="@drawable/ic_menu_send"
        app:useCompatPadding="true" />

    <android.support.design.widget.FloatingActionButton
        android:id="@+id/start_session_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="top|end"
        android:src="@drawable/ic_menu_send"
        app:layout_anchor="@id/add_assignment_button"
        app:layout_anchorGravity="top"
        app:useCompatPadding="true" />

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

输出

在此处输入图像描述


推荐阅读