我正在尝试制作一个透明状态栏和普通壁纸的活动。问题是状态栏和活动试图绘制不同的背景,每个都导致一个破旧的图像。
主题xml:fitssystemWindows - true
statusBarColor - @android:color/transparent
background - @drawable/backdrop
稍后我将使用精确的XML进行编辑。
图片(不能在这里上传图片):https://drive.google.com/file/d/0B4QbRXVog08OY1doazJmaTNoeGs/view?usp=docslist_api
EDIT 1:尝试使用下面建议的解决方案,仍然不起作用
主题xml:
<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:statusBarColor">@android:color/transparent</item>
</style>
activey_main .xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<ImageView
android:id="@+id/backgroundIV"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="@drawable/backdrop" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"/>
此时,应用程序显示如下:http://drive.google.com/file/d/0B4QbRXVog08OX25Ib1kteDJvazQ/view?usp=sharing
UPDATE- working code:
主题xml -
<style name="AppTheme" parent="android:Theme.Material.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="android:fitsSystemWindows">true</item>
<item name="android:background">@drawable/backdrop</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
活动布局xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
你应该在样式文件中半透明的状态栏和导航栏
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>
编辑:使用如下布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
tools:context="com.app.MainActivity" >
<ImageView
android:id="@+id/main_bg"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:scaleType="centerCrop"
android:src="@drawable/bg_main" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical" >
<!-- content here -->
</LinearLayout>
</RelativeLayout>