Mat*_*teo 5 android android-toolbar android-collapsingtoolbarlayout
在使用新的Android支持设计库时,在我的应用程序中尝试设置透明状态栏时,我遇到了一些问题.
具体来说,我正在使用CoordinatorLayout+ AppBarLayout+ CollapsingToolbarLayout+ Toolbar这种分层次序的组合.
我注意到状态栏首先是透明的然后我可以看到从透明到全黑的转换.
我在值/样式中这样做:
<item name="android:windowTranslucentStatus">true</item>
Run Code Online (Sandbox Code Playgroud)
这在我的布局中:
<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/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:elevation="4dp"
android:background="?android:colorPrimary"
android:layout_width="match_parent"
android:layout_height="128dp">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="64dp">
<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_collapseMode="pin"
app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
app:cardCornerRadius="4dp"
app:cardElevation="6dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Latest Stories"/>
<TextView
android:id="@+id/latest_story_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title Example"/>
<TextView
android:id="@+id/latest_story_preview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Content Example, this should be around 250 chars"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab_add_story"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:fabSize="normal"
app:layout_anchor="@id/appbar"
app:layout_anchorGravity="bottom|right|end"
app:borderWidth="0dp"
android:layout_margin="16dp"/>
<View
android:id="@+id/ripple_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
android:elevation="10dp"
android:stateListAnimator="@null"
android:clickable="false"/>
Run Code Online (Sandbox Code Playgroud)
(抱歉可怕的格式化,似乎SO编辑器不会合作)
这将在未来的版本中修复,还是有办法绕过这个?
感谢大家.
尝试设置半透明标志 - 它是在 api level 19 中添加的:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
Run Code Online (Sandbox Code Playgroud)
编辑:它不适用于低于 19 的 api 级别。(至少需要 KitKat)
| 归档时间: |
|
| 查看次数: |
6559 次 |
| 最近记录: |