【问题标题】:Status Bar Transparent not working properly透明状态栏无法正常工作
【发布时间】:2015-12-07 08:42:20
【问题描述】:

我正在尝试使用透明状态栏和通用壁纸制作活动。问题是状态栏和活动试图绘制不同的背景,每个背景都会导致图像破旧。

主题 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>

activity_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

更新工作代码

主题 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" >

【问题讨论】:

    标签: android android-5.0-lollipop material-design


    【解决方案1】:

    样式文件(v19及以上)中的状态栏和导航栏应该是半透明的

    <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>
    

    【讨论】:

    • 我也尝试过使用 windowTransluscentStatus,我仍然得到相同的结果,虽然它有一点改进但并不完美。
    • 我在我的答案中添加了一个示例布局。您应该使用 android:fitsSystemWindows="true" 将 ImageView 置于布局之外。
    • 仍然无法正常工作,现在状态栏显示为半透明白色。
    • 不知何故,一切都开始工作了。我已经接受了你的回答。谢谢大佬。
    猜你喜欢
    • 2016-09-06
    • 2012-01-29
    • 1970-01-01
    • 2015-07-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多