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

在尝试使用AnkoDSL替代Android Studio项目中的默认XML布局时,遇到状态栏颜色变化的问题。当使用XML布局时,状态栏显示为蓝色,但切换到AnkoDSL后,状态栏变为白色。尽管AnkoDSL代码与XML布局几乎相同,问题依然存在。已确认主题、颜色等设置未改变,且在XML布局下一切正常,暗示问题可能出在AnkoDSL的实现上。
摘要由CSDN通过智能技术生成

为了用anko DSL测试kotlin我决定在最后一个

android studio ide(2.1.3)中使用kotlin插件(1.0.3)和最新的anko库(0.9)开始一个新的proyect

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

这是xml:

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

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:layout_height="wrap_content"

android:layout_width="match_parent"

android:theme="@style/AppTheme.AppBarOverlay">

android:id="@+id/toolbar"

android:layout_width="match_parent"

android:layout_height="?attr/actionBarSize"

android:background="?attr/colorPrimary"

app:popupTheme="@style/AppTheme.PopupOverlay" />

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

android:text="Hello World!"

android:layout_width="wrap_content"

android:layout_height="wrap_content" />

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

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

13db037ddaa024c0b36d98fd58388061.png

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

class MainActivityUi: AnkoComponent {

override fun createView(ui: AnkoContext) = 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

}

}

}

}

相反,我得到了这个白色状态栏:sKWfb.png

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

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

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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值