Tôi đang cố gắng để kết hợp windowTranslucentStatus
và AppBarLayout
với Toolbar
gắn cờ với app:layout_scrollFlags="scroll|enterAlways"
Sử dụng windowTranslucentStatus với Thanh công cụ ẩn
kiểm tra đồng thời trên API 18, 19 và 22 (từ trái sang).
Vấn đề là trên API cao nhất, nơi thanh công cụ là partialy thể nhìn thấy dưới thanh trạng thái. Tôi đã thử rất nhiều sự kết hợp của phong cách nhưng đây là gần nhất tôi nhận được.
Trong phong cách tôi sử dụng:
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="android:colorPrimary" tools:targetApi="lollipop">@color/primary</item>
<item name="android:colorPrimaryDark" tools:targetApi="lollipop">@color/primary_dark</item>
<item name="colorPrimary">@color/primary</item>
<item name="colorPrimaryDark">@color/primary_dark</item>
<item name="colorAccent">@color/primary</item>
<item name="android:colorAccent" tools:targetApi="lollipop">@color/primary</item>
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
<item name="android:windowBackground">@color/background</item>
<item name="android:windowActionBarOverlay">true</item>
<item name="android:windowContentOverlay">@null</item>
</style>
Đây là xml bố trí của tôi:
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinator_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:minHeight="?attr/actionBarSize"
app:layout_scrollFlags="scroll|enterAlways"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/background"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:backgroundTint="@color/green"
app:layout_anchor="@id/recycler_view"
app:layout_anchorGravity="bottom|right|end" />
Tôi tạo ra ứng dụng mẫu, trong đó có sẵn trên github
Có gì thiếu trong câu đố này không?
Điều đó thực sự có thể hoạt động ... sẽ kiểm tra sau –
Tách tốt, làm việc trên tất cả 3 API được tôi đề cập! :) –
Vui vì tôi có thể giúp :) – crysxd