2015-07-18 13 views
17

Tôi có một ứng dụng sử dụng fitsSystemWindows để có thể vẽ nền sau Navigation- và Status-Bar - tiếc là SnackBar dường như bỏ qua fitsSystemWindows = true từ container. Tôi luộc vấn đề xuống ứng dụng tối thiểu này:SnackBar và fitsSystemWindow

problem

phong cách:

<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> 

bố trí:

<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> 

hoạt động:

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 biết một số cách giải quyết?

tôi công bố ứng dụng tối thiểu để hiển thị các vấn đề ở đây: https://github.com/ligi/SnackBarFitsSystemWindowProblem

Trả lời

13

Snackbar sẽ luôn luôn tìm kiếm một CoordinatorLayout để neo mình trong: khi bạn không có một, nó sử dụng xem nội dung đầy đủ (mà trong trường hợp của bạn, bao gồm diện tích dưới thanh trạng thái) -. thêm một CoordinatorLayoutfitsSystemWindows=true nên làm điều đó

+0

Thao tác này có bị đổ xuống từ Phân đoạn không? Tôi có một mảnh mà tôi đẻ trứng Snackbar này mặc dù –

+0

@NeonWarge - Bạn có nghĩa là tầng lên từ một mảnh có xem được chứa trong một 'CoordinatorLayout'? Yup. – ianhanniballake

+0

có, trên thực tế, có điều gì đó làm rối tung nó lên. Nó không tôn trọng thuộc tính đó cho tôi:/Một ViewPager của nó trên một hoạt động với 4 đoạn. –

-2

Vâng Câu trả lời đúng là thêm android:paddingbottom="50dp" để CoordinatorLayout bạn mặc dù tôi không chắc chắn nếu tất cả các kích thước của thanh điều hướng là 50 dp

-1

Bạn cũng có thể sử dụng dòng sau ở vị trí của bất kỳ CoordinatorLayout trong Snackbar khai với findViewById (android.support.design.R.id.design_navigation_view).

Các vấn đề liên quan