android– 状态栏不透明但是白色

android– 状态栏不透明但是白色,第1张

概述为了用ankoDSL测试kotlin我决定在最后一个androidstudioide(2.1.3)中使用kotlin插件(1.0.3)和最新的anko库(0.9)开始一个新的proyect我使用默认的proyectNavigationDrawerActivity,所以我只需要将主xml转换为anko.这是xml:<?xmlversion="1.0"encoding="utf-8"?><androi

为了用anko DSL测试kotlin我决定在最后一个android studio IDe(2.1.3)中使用kotlin插件(1.0.3)和最新的anko库(0.9)开始一个新的proyect

我使用默认的proyect Navigation Drawer Activity,所以我只需要将主xml转换为anko.

这是xml:

<?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">    <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.support.design.Widget.AppbarLayout            androID:layout_height="wrap_content"            androID:layout_wIDth="match_parent"            androID:theme="@style/Apptheme.AppbarOverlay">            <androID.support.v7.Widget.Toolbar                androID:ID="@+ID/toolbar"                androID:layout_wIDth="match_parent"                androID:layout_height="?attr/actionbarSize"                androID:background="?attr/colorPrimary"                app:popuptheme="@style/Apptheme.PopupOverlay" />        </androID.support.design.Widget.AppbarLayout>        <relativeLayout            xmlns:androID="http://schemas.androID.com/apk/res/androID"            xmlns:tools="http://schemas.androID.com/tools"            xmlns:app="http://schemas.androID.com/apk/res-auto"            androID:layout_wIDth="match_parent"            androID:layout_height="match_parent"            androID:paddingleft="@dimen/activity_horizontal_margin"            androID:paddingRight="@dimen/activity_horizontal_margin"            androID:paddingtop="@dimen/activity_vertical_margin"            androID:paddingBottom="@dimen/activity_vertical_margin"            app:layout_behavior="@string/appbar_scrolling_vIEw_behavior" >            <TextVIEw                androID:text="Hello World!"                androID:layout_wIDth="wrap_content"                androID:layout_height="wrap_content" />        </relativeLayout>    </androID.support.design.Widget.CoordinatorLayout>    <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"        app:headerLayout="@layout/nav_header_main"        app:menu="@menu/activity_main_drawer" /></androID.support.v4.Widget.DrawerLayout>

正如你在这里看到的那样,它工作得很好:


使用anko,我尝试从xml复制每个细节,获取此代码:

class MainActivityUi: AnkoComponent<MainActivity> {    overrIDe fun createVIEw(ui: AnkoContext<MainActivity>) = with(ui) {        drawerLayout {            ID = R.ID.drawer_layout            fitsSystemwindows = true            coordinatorLayout {                appbarLayout(R.style.Apptheme_AppbarOverlay) {                    toolbar {                        ID = R.ID.toolbar                        backgroundcolor = colorAttr(R.attr.colorPrimary)                        popuptheme = R.style.Apptheme_PopupOverlay                    }.lparams(height=dimenAttr(R.attr.actionbarSize),wIDth=matchParent)                }.lparams(wIDth=matchParent)                relativeLayout {                    padding = dip(16)                    textVIEw("Hello World!")                }.lparams(height=matchParent,wIDth=matchParent) {                   behavior = AppbarLayout.ScrollingVIEwBehavior()                }            }.lparams(height=matchParent,wIDth=matchParent)            navigationVIEw {                ID = R.ID.nav_vIEw                inflateheaderVIEw(R.layout.nav_header_main)                inflateMenu(R.menu.activity_main_drawer)            }.lparams(height=matchParent) {                gravity = Gravity.START                fitsSystemwindows = true            }        }    }}

相反,我得到了这个白色状态栏

我做的唯一更改是在MainActivity中将setContentVIEw(R.layout.activity_main)更改为MainActivityUi.setContentVIEw(this).

所以,我的问题是,当它们是相同的视图和布局时,为什么会发生这种情况?我该如何解决这个问题?

编辑:我正在使用在AndroID Studio中创建的默认项目,您选择新的项目,然后选择DrawerNavigationActivity.如果在setContentVIEw中我选择显示xml的视图,状态栏是蓝色的(第一个屏幕截图),但如果我选择显示anko的视图,我会得到白色状态栏.

在这两种情况下,我使用相同的主题,颜色等,当使用xml布局时,一切都运行完美,所以它必须是一个anko的问题

解决方法:

试着做

window.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
    WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)

在onCreate()里面

它对我有用

Reference

编辑:
也是我的代码

drawerLayout {  lparams(wIDth = matchParent, height = matchParent)  coordinatorLayout {     setpadding(0, dip(24), 0, 0)     appbarLayout {        toolbar {           backgroundcolor = primarycolor           setTitleTextcolor(primarycolorText)        }.lparams(wIDth = matchParent, height = dip(toolbar_size))     }.lparams(wIDth = matchParent, height = dip(toolbar_size))  }.lparams(wIDth = matchParent, height = matchParent)  navigationVIEw {  }.lparams(wIDth = dip(302), height = matchParent) {     gravity = Gravity.START  }}
总结

以上是内存溢出为你收集整理的android – 状态栏不透明但是白色全部内容,希望文章能够帮你解决android – 状态栏不透明但是白色所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1117328.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-29
下一篇2022-05-29

发表评论

登录后才能评论

评论列表(0条)

    保存