gpt4 book ai didi

android - 如何将ImageView带在透明的Status Bar下

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:15:36 24 4
gpt4 key购买 nike

在下图中,我试图将 ImageView 置于 StatusBar 之下。但它没有发生。

Image Screenshot on Android API 19

Image Screenshot on Android API 22

我继续Android transparent status bar and actionbar (这个问题)并试图实现相同但它不起作用。

Activity 的xml布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:id="@+id/category_layout_top"
android:fitsSystemWindows="true"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:fitsSystemWindows="true"
android:layout_width="390dp"
android:layout_height="390dp"
android:id="@+id/category_Image_View"/>


<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/def_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="#00FFFFFF"
android:layout_alignParentTop="true" />




</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="@+id/category_linearlayout">
<TextView android:layout_width="match_parent"
android:layout_height="match_parent"
android:singleLine="true"
android:id="@+id/category_textView"
/>
</LinearLayout>

</LinearLayout>

</FrameLayout>

我也在 onCreate() 方法中尝试了下面的代码

 setStatusBarTranslucent(true);



protected void setStatusBarTranslucent(boolean makeTranslucent) {
if (makeTranslucent) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
} else {
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}

style.xml

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>

</style>

style-v21.xml

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>

AppTheme 是 Activity 中使用的样式。

编辑 1

我在 FrameLayout 的背景中使用了一种颜色来检查它是否在状态栏下方。而事实并非如此。

所以我想问题不在于布局。

编辑 2这是期望的结果

最佳答案

在 style-v21 中,您覆盖了 AppTheme.NoActionBar 样式,但您说您在 Activity 中使用的样式是 AppTheme 样式。

您需要覆盖 style-v21 中的 AppTheme 布局或在您的 Activity 中定义 AppTheme.NoActionBar。

关于android - 如何将ImageView带在透明的Status Bar下,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35961333/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com