2015-03-30 14 views
6

Ich benutze die Bibliothek https://github.com/futuresimple/android-floating-action-button, um die Fab-Tasten zu erstellen, die ziemlich gut funktioniert. Ich habe mehrere Bibliotheken ausprobiert, aber keiner verwendet den Effekt, der in den meisten Anwendungen mit einer Fab (oder Google-Apps wie halten, Posteingang) verwendet wird, wenn der Hintergrund der gesamten Anwendung halbtransparent weiß oder schwarz wird, hängt es ab. Ich kann keinen Weg finden, es zu tun. Ist es möglich, ein Beispiel oder etwas Ähnliches zu haben, um diese Art von Effekt zu erzielen? Sie können sehen, was ich in diesem Bild bedeuten: enter image description hereAlpha-Hintergrund auf FAB geklickt

Der halb schwarzer Hintergrund

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" > 

    <RelativeLayout 
     android:id="@+id/content_frame" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 

     <include 
      android:id="@+id/toolbar" 
      layout="@layout/toolbar" /> 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/semi_white_bg" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@color/white_semi_transparent" 
     android:visibility="gone" > 
    </RelativeLayout> 

    <RelativeLayout 
     android:id="@+id/listFrame" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/content_frame" 
     android:visibility="gone" > 

     <TextView 
      android:id="@+id/status" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="@color/cabinet_color" 
      android:fontFamily="sans-serif" 
      android:gravity="center_vertical" 
      android:paddingBottom="8dp" 
      android:paddingLeft="16dp" 
      android:paddingRight="16dp" 
      android:paddingTop="8dp" 
      android:textColor="#fff" 
      android:textSize="17sp" 
      android:visibility="gone" /> 

     <android.support.v7.widget.RecyclerView 
      android:id="@android:id/list" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_below="@+id/status" 
      android:clipToPadding="false" 
      android:scrollbars="vertical" /> 

     <LinearLayout 
      android:id="@android:id/empty" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_centerInParent="true" 
      android:orientation="vertical" > 

      <ImageView 
       android:id="@+id/emptyImage" 
       android:layout_width="96dp" 
       android:layout_height="96dp" 
       android:layout_gravity="center_horizontal" 
       android:layout_marginBottom="16dp" 
       android:scaleType="fitXY" 
       android:src="?empty_image" /> 

      <TextView 
       android:id="@+id/emptyText" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_gravity="center_horizontal" 
       android:layout_marginLeft="16dp" 
       android:layout_marginRight="16dp" 
       android:fontFamily="sans-serif-light" 
       android:gravity="center" 
       android:lineSpacingMultiplier="1.4" 
       android:paddingBottom="16dp" 
       android:text="@string/no_files" 
       android:textColor="?empty_text" 
       android:textSize="22sp" /> 
     </LinearLayout> 
    </RelativeLayout> 

    <ProgressBar 
     android:id="@android:id/progress" 
     style="?android:progressBarStyle" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:indeterminateOnly="true" /> 

</RelativeLayout> 

dies mein layout.xml ist aber die Arbeit scheint überhaupt nicht, wie ich want.Seems, dass nicht die gesamte überlappt Aussicht, aber nur Farben, was es will ..

+0

Sie nicht bekommen, beschreiben Sie einfach Problem in einfacher Form. – Harry

Antwort

2

Zufrieden Ihre Frage ...

diese Bibliothek wird u nicht zulassen, setzen Schaltfläche Click-Ereignis hinzufügen, können Sie für Ihre eigene Bibliothek Code ändern müssen können, verwenden Sie diese Idee: Verwenden Sie Relatie oder framelayout und fügen Sie diesen schwarzen Hintergrund oder Bild hinter FAB hinzu.

jetzt in der Bibliothek Klasse FloatingActionsMenu.class diesen Code finden und kommentieren:

//mAddButton.setOnClickListener(new OnClickListener() 
//{ 
// @Override 
// public void onClick(View v) 
// { 
//  toggle(); 
// } 
//}); 

Dann fügen Sie diese Methode in dieser Klasse,

public void setAddButtonClickListener(OnClickListener listener) 
{ 
mAddButton.setOnClickListener(listener); 
} 

definieren Klick Zuhörer in Ihre Tätigkeit wie

OnClickListener listener = new OnClickListener() 
{ 
    @Override 
    public void onClick(View v) 
    { 
     if (floatingActionMenuButton.isExpanded()) 
     {//make the background visible 
     } 
     else 
     {//make the background invisible 
     } 
     floatingActionMenuButton.toggle(); 
    } 
}; 

und übergeben Sie es an FAB

floatingActionMenuButton.setAddButtonClickListener(listener); 

Baue Bibliothek und Projekt, Hoffe das wird helfen!

+0

Ihre Idee scheint korrigiert .. Nur eine Sache .. wie Sie sehen können, das FloatingActionMenuButton ist die "Haupt" fab, wenn Sie die anderen FloatingActionButtons öffnen. Wenn ich diese Zeilen kommentieren. Es funktioniert immer noch? Ich meine, es wird die anderen schwebenden Schaltflächen öffnen oder einfach den Hintergrund erstellen? Ich hoffe ich habe mich nicht zwischen ihnen entschieden.Ich hätte beide Funktionalität –

+1

floatingActionMenuButton.toggle(); In Click Listener öffnen oder schließen Sie andere Menü-Schaltflächen und Sie können auch den Hintergrund gleichzeitig ändern. – Harry

+0

Das sind erstaunliche Neuigkeiten. Perfekt, sobald ich zuhause bin, versuche ich Ihre Lösung. In der Zwischenzeit, danke –

4

fand ich heraus, das die einfachste Lösung meiner Meinung nach sein, und es funktioniert perfekt:

fam.setOnFloatingActionsMenuUpdateListener(new FloatingActionsMenu.OnFloatingActionsMenuUpdateListener() { 
     @Override 
     public void onMenuExpanded() { 
      dimmedBackground.setVisibility(View.VISIBLE); 
     } 

     @Override 
     public void onMenuCollapsed() { 
      dimmedBackground.setVisibility(View.GONE); 
     } 
    }); 
+0

Ich werde versuchen, danke. –

+0

super nett verwendet i-Code aus dieser Bibliothek https://github.com/Clans/FloatingActionButton und für gleiche Arbeit ist der Code für diese Bibliothek: floatingActionMenu.setOnMenuToggleListener (neu FloatingActionMenu.OnMenuToggleListener() { @Override public void onMenuToggle (boolean geöffnet) { displayToast ("geöffnet" + geöffnet); } }); –

1

Sie benötigen eine Aktivität in einem FrameLayout wickeln. FrameLayout sollte 2 Kinder haben

  • Ihre Aktivität Inhalt
  • Ein weiterer Framelayout FloatingActionsMenu enthält

Hier ist der relevante Code-Schnipsel.

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:fab="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="in.city.bytes.view.MainActivity"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical"> 
    <!-- other content in the activity --> 
</LinearLayout> 

<FrameLayout 
    android:id="@+id/frame_layout" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@color/white_overlay"> 
    <!-- floating action menu with buttons --> 
</FrameLayout> 

In Ihrer Tätigkeit, ändern Sie die Alpha-Version von frame_layout wenn FAB-Menü angeklickt wird. Ich habe auch einen Blog geschrieben, der es erklärt. http://www.rishabhsinghal.in/implement-floating-action-button-similar-to-inbox-by-gmail-or-evernote/

+0

Was ist der Farbcode von white_overlay? –