gpt4 book ai didi

android:windowTranslucentStatus/fitsSystemWindows 工具栏大小错误

转载 作者:行者123 更新时间:2023-11-29 23:46:50 27 4
gpt4 key购买 nike

尝试创建一个带有半透明状态栏和工具栏的简单 View ,但无法让工具栏按我预期的方式运行。工具栏似乎将 fitsSystemWindows bool 属性用于它的内部项目(标题、溢出菜单),但不是用于它的实际位置。

我可以通过编程方式获取状态栏的大小并通过添加状态栏高度来调整工具栏的大小,但我的理解是 fitsSystemWindows=true 应该这样做。

Lollipop Screenshot

主题

    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

<style name="AppTheme.NoActionBar">
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
<item name="android:windowTranslucentStatus" tools:targetApi="kitkat">true</item>
</style>

布局 - 注意:我将背景移动到 AppBarLayout,因为最终目标是在工具栏后面有一个背景图像。如果背景是在 AppBarLayout 或工具栏上定义的,则不会更改结果。

<?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"
tools:context=".MainActivity">

<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:fitsSystemWindows="true"
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:fitsSystemWindows="true"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</android.support.design.widget.AppBarLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Content Here"
android:gravity="center"/>

</android.support.design.widget.CoordinatorLayout>

只是希望有一个我遗漏的简单的东西可以使这项工作按照我的理解进行。添加 fitsSystemWindows 属性会将标题和溢出菜单向下移动,但工具栏会被截断,因为它没有被移动。

最佳答案

工具栏布局更改为 wrap_content 的高度似乎“解决”了这个问题。

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
app:popupTheme="@style/AppTheme.PopupOverlay" />

关于android:windowTranslucentStatus/fitsSystemWindows 工具栏大小错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51256210/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com