10

Chcę użyć FAB z półprzezroczystym kolorem tła. Ale otrzymuję FAB w dwóch różnych kolorach. Jaki jest problem?Android Floating Action Button Semi Transparent Background Color

<android.support.design.widget.FloatingActionButton 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="bottom|left" 
    android:fadingEdgeLength="5dp" 
    app:borderWidth="0dp" 
    app:elevation="4dp" 
    app:backgroundTint="#99f03456" 
    app:fabSize="normal"/> 

enter image description here

i bez rozciągliwej.

enter image description here

+0

spróbować stworzyć ten kolor w '' color.xml' i używać aplikacji: backgroundTint = "@ kolor/yourcolor" ' –

+0

@ kolor/akcent zdefiniować kolor stylu motywu w projekcie –

+0

@BOUTERBIATOualid nie różnica. – Mbt925

Odpowiedz

5

tu mamy ten sam problem. Próbowałem ustawić przezroczystość alfa w xml przy użyciu backgroundTint, ale to nie zadziałało i spowodowało taki sam wygląd jak na screenach (dwa okręgi).

Tak ustawić go w kodzie tak:

floatingButton = (FloatingActionButton) findViewById(R.id.fab); 
floatingButton.setAlpha(0.25f); 

i wygląd jest teraz spójne.

+0

to działa, ale dzięki temu ikona jest przezroczysta ...: - / – lenooh

1

ile elewacja jest to konieczne, można usunąć „wewnętrznego kręgu” poprzez ustawienie go na 0:

app:elevation="0dp" 
1

udało mi się rozwiązać problemu przy użyciu Jerzy Chalupski przycisk pływających Działanie: https://github.com/futuresimple/android-floating-action-button

do wykorzystania w projekcie dodać:

compile 'com.getbase:floatingactionbutton:1.10.1' 

do zależności,

a następnie dodać:

<com.getbase.floatingactionbutton.FloatingActionButton 
      android:id="@+id/my_fab" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginTop="12dp" 
      android:layout_marginRight="8dp" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentRight="true" 
      android:onClick="myMethod" 
      fab:fab_icon="@drawable/my_icon" 
      fab:fab_colorNormal="@color/my_transparent_color" 
      fab:fab_colorPressed="@color/white" 
      /> 

do pliku XML.

Działa

2

Set elewacja i pressedTranslationZ zera do usunięcia skutków

<android.support.design.widget.FloatingActionButton 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:onClick="onClickMyLocation" 
    app:backgroundTint="@color/transparentColor" 
    app:srcCompat="@drawable/ic_my_location" 
    app:elevation="0dp" 
    app:pressedTranslationZ="0dp"/>