Abh*_*tha 5 xml android transparent statusbar android-framelayout
在下面的图片中,我试图将 ImageView 置于 StatusBar 下。但它没有发生。
我继续使用Android 透明状态栏和操作栏(this question)并尝试实现相同但不起作用。
活动的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>
Run Code Online (Sandbox Code Playgroud)
我也在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);
}
}
Run Code Online (Sandbox Code Playgroud)
样式文件
<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>
Run Code Online (Sandbox Code Playgroud)
样式-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>
Run Code Online (Sandbox Code Playgroud)
AppTheme 是活动中使用的样式。
编辑 1
我在 FrameLayout 的背景中使用了一种颜色来检查它是否在状态栏下方。事实并非如此。
所以问题不在于布局,我猜。
在 style-v21 中,您将覆盖样式 AppTheme.NoActionBar,但您说您在活动中使用的样式是 AppTheme 样式。
您需要覆盖 style-v21 中的 AppTheme 布局或在 Activity 中定义 AppTheme.NoActionBar。
| 归档时间: |
|
| 查看次数: |
2627 次 |
| 最近记录: |