但是,我希望我的DrawerLayout看起来像这样:
我可以使用以下行:
<item name="androID:windowTranslucentStatus">true</item>
但是,我的问题不在于我无法设置状态栏的透明度.我的问题是状态栏和 *** 作栏颜色的动态更改不适用于windowTranslucentStatus.即使我调用了getwindow().setStatusbarcolor(),我的状态栏颜色仍然是colorPrimaryDark(上图中状态栏上可见的芥黄色).
现在,我跟随this教程和this和this堆栈溢出问题,但无法解决问题.所有这些文章都说,一旦我将windowTranslucentStatus设置为true,Actionbar将移动到状态栏下方的顶部(以便状态栏与 *** 作栏重叠).之后,我应该能够在 *** 作栏中添加一些填充,只需更改 *** 作栏颜色也会导致颜色相同的深色状态栏,因为状态栏实际上是半透明的并且与我的 *** 作栏重叠.但是,出于某种原因,在我的情况下不会发生这种情况.无论我将fitsSystemwindows设置为true还是false,或者完全删除该属性, *** 作栏都会保留在原来的位置. *** 作栏始终位于状态栏下方,当然,如果我设置透明度,则该状态栏始终为黄色.
我还尝试以编程方式更改状态栏颜色时设置Alpha.这确实使状态栏有点透明,但它看起来很奇怪,因为它不再是黑暗.删除CoordinatorLayout也没有任何帮助.我花了几个小时试图解决这个问题,现在感到非常沮丧.任何帮助是极大的赞赏.
我的activity_main:
<?xml version="1.0" enCoding="utf-8"?><androID.support.v4.Widget.DrawerLayout 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:ID="@+ID/drawer_layout"androID:layout_wIDth="match_parent"androID:layout_height="match_parent"androID:fitsSystemwindows="true"tools:openDrawer="start"><include layout="@layout/app_bar_main" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" /><androID.support.design.Widget.NavigationVIEw androID:ID="@+ID/nav_vIEw" androID:layout_wIDth="wrap_content" androID:layout_height="match_parent" androID:layout_gravity="start" androID:fitsSystemwindows="true"> <include layout="@layout/nav_header_main" /> <androID.support.v7.Widget.RecyclerVIEw androID:ID="@+ID/nav_menu_recyclervIEw" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:layout_margintop="@dimen/nav_header_height" androID:clipTopadding="false" androID:paddingleft="@dimen/activity_horizontal_margin" androID:paddingRight="@dimen/activity_horizontal_margin" androID:paddingtop="@dimen/size_14dp" app:layoutManager="linearlayoutmanager" /></androID.support.design.Widget.NavigationVIEw></androID.support.v4.Widget.DrawerLayout>
这是我的app_bar_main的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.design.Widget.AppbarLayout androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" androID:theme="@style/Apptheme.AppbarOverlay" app:elevation="0dp"> <FrameLayout androID:ID="@+ID/toolbar_container" androID:layout_wIDth="match_parent" androID:layout_height="?attr/actionbarSize" app:popuptheme="@style/Apptheme.PopupOverlay"> <androID.support.v7.Widget.Toolbar androID:ID="@+ID/toolbar" androID:layout_wIDth="match_parent" androID:layout_height="?attr/actionbarSize" androID:background="?attr/colorPrimary" /> <com.quintype.sakshipost.Widgets.CustomMaterialSearchVIEw androID:ID="@+ID/search_vIEw" androID:layout_wIDth="match_parent" androID:layout_height="wrap_content" /> </FrameLayout></androID.support.design.Widget.AppbarLayout><include layout="@layout/content_main" /></androID.support.design.Widget.CoordinatorLayout>解决方法 您的问题是由于getwindow().setStatusbarcolor()与DrawerLayout无法正常工作引起的.为了使您的状态栏保持半透明以及能够更改其颜色,您必须按照以下过程 *** 作:
在v21 / styles.xml文件中添加/修改以下主题,如下所示:
<style name="Apptheme.NoActionbar" parent="Apptheme"> <item name="windowActionbar">false</item> <item name="windowNoTitle">true</item> <item name="androID:windowTranslucentStatus">true</item></style>
这是标准DrawerLayout使用的主题(当然,假设您在具有DrawerLayout的活动中使用此主题).如您所知,这将使您的状态栏保持半透明状态.
接下来,从app_bar_main中的CoordinatorLayout中删除androID:fitsSystemwindows =“true”.
接下来,无论您在何处更改工具栏/状态栏的颜色,请使用与工具栏相同的颜色使用drawerLayout.setStatusbarBackground(colorDrawable)(当然,假设对DrawerLayout的引用称为drawerLayout).请注意,drawerLayout.setStatusbarBackground()方法采用Drawable对象,与window.setStatusbarcolor()方法不同,后者采用int颜色,因此您可能需要使用以下内容将颜色转换为drawable:
new colorDrawable(ContextCompat.getcolor(getApplicationContext(),R.color.colorPrimary))
这将确保您的状态栏是半透明的,并使其能够更改颜色.希望你能够让这个工作.
总结以上是内存溢出为你收集整理的Android:具有动态actionBar颜色和DrawerLayout的透明状态栏全部内容,希望文章能够帮你解决Android:具有动态actionBar颜色和DrawerLayout的透明状态栏所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)