我希望在我的应用程序中能够实现这个效果:
其中状态栏是半透明的,布局在状态栏后面。我读过的关于这个主题的每个例子都主要与抽屉导航相关联,并且主要使用 ScrimInsetScrollView(或 ScrimInsetsFrameLayout)。我尝试使用 ScrimInsetsFrameLayout 实现它。
基本上我有一个包含 fragment 的 Activity ,这是我的布局( fragment 稍后添加到 Activity 的 onCreate 方法中的容器):
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:fitsSystemWindows="true"
>
<com.test.app.widget.ScrimInsetsFrameLayout
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:insetForeground="#4000"
android:id="@+id/container"
></com.test.app.widget.ScrimInsetsFrameLayout>
</FrameLayout>
而且我还在主题中将 android:statusBarColor 设置为透明。 该解决方案对我不起作用。显然我在这里做错了什么。 有人可以指出我错在哪里吗?
最佳答案
你试过吗
@Override
public void onCreate(Bundle savedInstanceState) {
getWindow().requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
如 Android documentation 中所述
关于android - 状态栏后面的布局 - Android Lollipop,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28945860/