如果我使用
启用半透明导航栏getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
然后工具栏位于状态栏后面(状态栏应该是彩色的,但导航栏应该是半透明的)。但是,如果我转到此活动的布局XML并放入android:fitsSystemWindows="true"
,工具栏将正确布局,但导航栏则为纯色。
这是布局:
<?xml version="1.0" encoding="utf-8"?>
<me.ccrama.redditslide.Views.SidebarLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:background="?attr/activity_background">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="@+id/anchor"
android:layout_width="1dp"
android:layout_marginTop="4dp"
android:layout_marginRight="3dp"
android:layout_gravity="top|right"
android:layout_height="1dp" />
<me.ccrama.redditslide.Views.ToggleSwipeViewPager
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<android.support.design.widget.AppBarLayout
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:minHeight="56dp"
android:layout_height="?android:attr/actionBarSize"
android:theme="@style/ActionBarCompat"
android:title="@string/app_name" />
<ViewStub
android:id="@+id/stub_tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inflatedId="@+id/sliding_tabs"
android:layout="@layout/activity_overview_tabs" />
</android.support.design.widget.AppBarLayout>
</FrameLayout>
<ListView
android:id="@+id/drawerlistview"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="?attr/card_background"
android:orientation="vertical" />
<include
layout="@layout/subinfo"
android:layout_width="300dp"
android:layout_height="match_parent"
android:layout_gravity="end" />
</me.ccrama.redditslide.Views.SidebarLayout>
如果我将android:fitsSystemWindows="true"
放在FrameLayout
内,则会发生相同的行为(彩色导航栏)。
下面的第一张图片是工具栏布局混乱的时候,第二张手机是导航栏不是半透明的时候。
答案 0 :(得分:1)
使用以下主题作为您的活动主题:
Declaration 1: int jimmy [HEIGHT][WIDTH];
Accessing 1: jimmy[n][m]
Declaration 2: int jimmy [HEIGHT * WIDTH];
Accessing 2: jimmy[n*WIDTH+m]
并使用getNavigationBarColor(Color.TRANSPARENT);
窗口管理
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
窗口
/**
* Flag indicating that this Window is responsible for drawing the background for the
* system bars. If set, the system bars are drawn with a transparent background and the
* corresponding areas in this window are filled with the colors specified in
* {@link Window#getStatusBarColor()} and {@link Window#getNavigationBarColor()}.
*/
public static final int FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS = 0x80000000;
/**
* Window flag: request a translucent status bar with minimal system-provided
* background protection.
*
* <p>This flag can be controlled in your theme through the
* {@link android.R.attr#windowTranslucentStatus} attribute; this attribute
* is automatically set for you in the standard translucent decor themes
* such as
* {@link android.R.style#Theme_Holo_NoActionBar_TranslucentDecor},
* {@link android.R.style#Theme_Holo_Light_NoActionBar_TranslucentDecor},
* {@link android.R.style#Theme_DeviceDefault_NoActionBar_TranslucentDecor}, and
* {@link android.R.style#Theme_DeviceDefault_Light_NoActionBar_TranslucentDecor}.</p>
*
* <p>When this flag is enabled for a window, it automatically sets
* the system UI visibility flags {@link View#SYSTEM_UI_FLAG_LAYOUT_STABLE} and
* {@link View#SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN}.</p>
*/
public static final int FLAG_TRANSLUCENT_STATUS = 0x04000000;
答案 1 :(得分:0)
来自doc
如果您要创建自定义主题,请将其中一个主题设置为 父主题或包含windowTranslucentNavigation和 您主题中的windowTranslucentStatus样式属性。
所以你可以使用以下主题,但是对于Api 19 +:
值
<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
</style>
<style name="Base.Theme.DesignDemo" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">#673AB7</item>
<item name="colorPrimaryDark">#512DA8</item>
<item name="colorAccent">#FF4081</item>
<item name="android:windowTranslucentNavigation">true</item>
</style>
值-21:
<style name="Theme.DesignDemo" parent="Base.Theme.DesignDemo">
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
</style>