2015-07-18 8 views
17

Ich habe eine App, die mit fitsSystemWindows einen Hintergrund hinter Navigations- und Statusleiste zeichnen kann - leider ignoriert die SnackBar die fitsSystemWindows = true aus dem Container. Ich gekocht, um das Problem auf diese minimale App:SnackBar und fitSystemWindow

problem

der Stil:

<resources> 

    <style name="AppTheme" parent="Theme.AppCompat.Light"> 

     <item name="android:windowBackground">@color/accent_material_dark</item> 
     <item name="android:fitsSystemWindows">false</item> 

     <item name="android:windowTranslucentStatus">true</item> 
     <item name="android:windowTranslucentNavigation">true</item> 
    </style> 

</resources> 

das Layout:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       xmlns:tools="http://schemas.android.com/tools" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 

       android:fitsSystemWindows="true" 
       tools:context=".MainActivity"> 

    <Button 

      android:id="@+id/button" 
      android:text="@string/hello_world" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"/> 

</RelativeLayout> 

der Aktivität:

public class MainActivity extends AppCompatActivity { 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     findViewById(R.id.button).setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(final View v) { 
       Snackbar.make(v,"This Snackbar should fitSystemWindows",Snackbar.LENGTH_INDEFINITE).show(); 
      } 
     }); 
    } 

} 

Anyon e weiß eine Abhilfe?

veröffentlichte ich die minimale App hier das Problem zu zeigen: https://github.com/ligi/SnackBarFitsSystemWindowProblem

Antwort

13

Snackbar wird ein CoordinatorLayout sucht immer selbst zu verankern, in: Wenn Sie noch kein Konto haben, verwendet er die gesamte Inhalt Ansicht (die in Ihr Fall umfasst den Bereich unter der Statusleiste.) - ein CoordinatorLayout hinzufügen, die fitsSystemWindows=true es tun soll

+0

Würde diese Kaskade von Fragment herunterkippen? Ich habe ein Fragment, in dem ich diese Snackbar spawne, aber –

+0

@NeonWarge - Sie meinen, Kaskade von einem Fragment, dessen Ansicht in einem 'CoordinatorLayout' enthalten ist? Jep. – ianhanniballake

+0

Ja, in der Tat, es gibt etwas, das es vermasselt. Es respektiert dieses Attribut nicht für mich:/Es ist ein ViewPager für eine Aktivität mit 4 Fragmenten. –

-2

Nun die richtige Antwort ist android:paddingbottom="50dp" zu Ihrem CoordinatorLayout hinzufügen, obwohl ich, wenn alle Navigationsleiste Größe nicht sicher bin, ist 50 dp

-1

Sie können auch die folgende Zeile anstelle jeder CoordinatorLayout in Snackbar Erklärung verwenden mit findViewById (android.support.design.R.id.design_navigation_view).