2016-05-28 5 views
2

Ich versuche, ein transparentes unteres Blatt-Layout zu machen, das mir erlauben würde, den Inhalt der Ansicht darunter zu sehen. Das untere Blatt funktioniert wie erwartet, aber wenn ich den Hintergrund auf @null oder @android:color/transparent setze, ist die Ansicht des Layouts weiß, im Gegensatz zu transparent. Mein Layout ist wie folgt:Transparentes unteres Blattlayout in Android

app_bar_main.xml:

<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:id="@+id/coordinatorLayout" 
    android:background="@android:color/transparent" 
    android:fitsSystemWindows="true" 
    tools:context=".core.activities.MainActivity"> 
    <!-- stuff here --> 
    <LinearLayout 
     android:id="@+id/bottom_sheet" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center" 
     android:background="@null" 
     android:orientation="vertical" 
     app:layout_behavior="@string/bottom_sheet_behavior"> 
    </LinearLayout> 

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

Das lineare Layout mit id bottom_sheet hält, na ja, mein unteres Blatt. Das Blatt selbst ist wie folgt definiert:

<?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:background="@null" 
    android:layout_height="match_parent"> 
    <LinearLayout android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@null" 
     android:orientation="vertical"> 

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/bottom_sheet_placeholder_layout" 
      android:layout_weight="0.6" 
      android:layout_width="match_parent" 
      android:background="@null" 
      android:layout_height="50dp" 
      android:orientation="horizontal"> 
     </LinearLayout> 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:id="@+id/bottom_sheet_layout" 
      android:layout_margin="0dp" 
      android:layout_weight="0.4" 
      android:layout_width="match_parent" 
      android:background="@color/my_background" 
      android:layout_height="wrap_content" 
      android:orientation="vertical"> 

      <ProgressBar 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:gravity="center" 
       android:id="@+id/my_progress_bar" /> 

      <TextView 
       android:layout_marginTop="5dp" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceLarge" 
       android:text="Large Text" 
       android:textColor="@color/my_text" 
       android:id="@+id/txt_my_info" 
       android:layout_gravity="center_horizontal" 
       android:visibility="gone" 
       android:textSize="48px" /> 

      <TextView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:textAppearance="?android:attr/textAppearanceMedium" 
       android:text="Medium Text" 
       android:id="@+id/txt_my_address" 
       android:textColor="@color/my_secondary_text" 
       android:visibility="gone" 
       android:layout_gravity="center_horizontal" /> 
     </LinearLayout> 
    </LinearLayout> 

    <android.support.design.widget.FloatingActionButton 
     android:id="@+id/btn_edit_tree_info" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:layout_marginTop="-62dp" 
     android:elevation="100dp" 
     android:src="@drawable/ic_create_black_24dp" 
     app:layout_anchor="@id/bottom_sheet_layout" 
     app:layout_anchorGravity="top|end|right" 
     app:useCompatPadding="true"/> 
</android.support.design.widget.CoordinatorLayout> 
+0

Was ist die Farbe von Android: background = "@ color/curio_background"? –

+0

Es ist Farbe ist # FFD162 :) – JB2

+0

Mögliche Duplikate von [Transparentes Layout in Android?] (Http://stackoverflow.com/questions/4285981/transparent-layout-in-android) – JB2

Antwort

0

in Ihrem color.xml erstellen: <color name="colorTransparent">#00000000</color> und verwenden android:background="@color/colorTransparent"

+0

Das ist das gleiche als mit '@android : color/transparent', was nicht funktioniert. '@android: color/transparent' ist definiert als' # 00000000 ' – JB2

+0

benutze es anstelle von' android: background = "@ null" ' –

+0

Danke, aber wie ich in der Frage gesagt habe Das Problem ist, dass dies nicht funktioniert :) – JB2

0

verfärben Hintergrund

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/bottom_sheet_placeholder_layout" 
     android:layout_weight="0.6" 
     android:layout_width="match_parent" 
     android:background="#00FFFFFF" 
     android:layout_height="50dp" 
     android:orientation="horizontal"> 
    </LinearLayout> 

Try it !!

+0

Danke Nguyễn. Ich habe es versucht, aber leider funktioniert das nicht. Das Problem besteht weiterhin ... – JB2

1

Fügen Sie diese in Ihrem bottomSheet setupDialog(final Dialog dialog, int style)

dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 

und fügen auch android:background="@android:color/transparent" Ansicht zu verankern

1
private void setupDialogBackground() { 
    getDialog().setOnShowListener(new DialogInterface.OnShowListener() { 
     @Override 
     public void onShow(DialogInterface dialog) { 
      BottomSheetDialog d = (BottomSheetDialog) dialog; 
      FrameLayout bottomSheet = (FrameLayout) d.findViewById(R.id.design_bottom_sheet); 
      if (bottomSheet == null) 
       return; 
      bottomSheetBehavior = BottomSheetBehavior.from(bottomSheet); 
      bottomSheet.setBackground(null); 
     } 
    }); 
} 
+0

funktioniert super! Die zweite Reihe vom Ende kann jedoch entfernt werden. – Shirane85

3

Die Antwort ist viel einfacher: nur diese Zeile

myDialog .getWindow() .findViewById(R.id.design_bottom_sheet) .setBackgroundResource(android.R.color.transparent);

Und nicht ändern sta ndard ids (R.id.design_bottom_sheet und android.R.color.transparent). Es macht Hintergrund von Bottom Sheet Dialog transparent

+0

Danke, aber ich musste decorView hinzufügen, damit es funktioniert. Kotlin-Beispiel: 'myDialog.window.decorView .findViewById (R.id.design_bottom_sheet) .setBackgroundResource (android.R.color.transparent)' –

Verwandte Themen