android - Android 中的半透明状态栏

标签 android android-layout android-view

我正在使用以下布局 (main_activity.xml)

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_margin="@dimen/text_margin"
        android:fitsSystemWindows="true"
        android:text="@string/large_text" />
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>

具有以下样式-v21

<resources>
<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>
    <item name="android:windowTranslucentStatus">true</item>
    <item name="android:windowTranslucentNavigation">true</item>
</style>
</resources>

但是我还是无法归档透明状态栏

看起来像这样

Non-Transparent

但我想要这样的东西(新的 Google 报亭应用程序)

Transparent status bar

注意:我正在使用

compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support:support-v4:25.1.1'
compile 'com.android.support:design:25.1.1'

最佳答案

试试这个:

将此添加到您的应用主题中:

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

android:fitsSystemWindows=”true”设置为根容器

现在在你的 onCreate() Activity 中:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        Window w = getWindow();
        w.setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }

已更新,结果:

enter image description here

您可以使 snackbar 在屏幕顶部绘制:

Snackbar snack = Snackbar.make(parentLayout, str, Snackbar.LENGTH_LONG);
View view = snack.getView();
FrameLayout.LayoutParams params =(FrameLayout.LayoutParams)view.getLayoutParams();
params.gravity = Gravity.TOP;
view.setLayoutParams(params);
snack.show();

有关详细信息,请参阅 here

关于android - Android 中的半透明状态栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42313382/

相关文章:

android - 如何使我的表单在 Android 中可滚动?

android - 如何确定应用程序是在平板电脑还是移动设备上运行?

android - ListView 的最后一项 : Fab hides it

android - 了解 BaseAdapter 以及如何使用它们

android - 是否可以在 AppBar/CollapsingToolbarLayout 之外设置 Collapsing 布局?

android - View 绑定(bind)迁移导致的代码重复

java - Android中如何确定两个 View 的公共(public)父 View

android - "Could not find a method .. in the activity class .. for onClick handler"

java - 字数统计给出的计数与原始计数不同

android - Android 中复杂的自定义按钮状态