【问题标题】:Screen always fit System Windows in Android Material Drawer屏幕始终适合 Android Material Drawer 中的系统 Windows
【发布时间】:2017-05-07 23:06:56
【问题描述】:

我正在开发一个 Android 应用程序。在我的应用程序中,我使用材料抽屉-https://github.com/mikepenz/MaterialDrawer 在左侧设置抽屉。我可以轻松地设置抽屉。但它有问题。它总是适合系统窗口,如下面的屏幕截图所示。

这就是我在活动中设置抽屉的方式。

private void setUpLeftDrawer()
    {
        DrawerBuilder builder = new DrawerBuilder()
                .withActivity(this)
                .withToolbar(toolbar);
        if(areas!=null && areas.size()>0)
        {

            for(Area area: areas)
            {
                PrimaryDrawerItem item = new PrimaryDrawerItem().withIdentifier(area.getId()).withName(area.getName());
                builder.addDrawerItems(item);
            }
        }

        builder.build();
    }

这是我的 main_activity xml。

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:fitsSystemWindows="false"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- This LinearLayout represents the contents of the screen  -->


        <!-- The ActionBar displayed at the top -->
        <android.support.design.widget.AppBarLayout
            android:id="@+id/appbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
            <android.support.v7.widget.Toolbar
                android:fitsSystemWindows="false"
                android:id="@+id/toolbar"
                android:minHeight="?attr/actionBarSize"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                app:titleTextColor="@android:color/white"
                >
            </android.support.v7.widget.Toolbar>
        </android.support.design.widget.AppBarLayout>

        <!-- The main content view where fragments are loaded -->


</RelativeLayout>

所以,我不希望它适合系统 Windows。如何修复我的代码不适合系统窗口?

我也尝试在样式 XML 中设置它

<item name="android:fitsSystemWindows">false</item>

效果不好。

【问题讨论】:

  • true
  • 我不想安装系统 Windows @DushyantSuthar。我尝试修复 xml 样式主题。但它不像我提到的那样工作。
  • 您的问题已经解决了吗?为什么你不想使用 fitSystemWindows=true?你看过样品吗?
  • 问题是因为我在网络异步调用的回调中设置了抽屉。所以你需要在通话之前进行设置。

标签: android android-drawer materialdrawer


【解决方案1】:

删除&lt;item name="android:windowTranslucentStatus"&gt;true&lt;/item&gt; 来自 values-v21 样式

<!-- Base application theme. -->
    <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>
        <item name="android:windowTranslucentStatus">true</item><!--this-->
    </style>

【讨论】:

  • 那行不包括在我的风格主题中。也没有值 21。
  • 是否以编程方式设置?
  • 是的,我知道为什么了??我正在发出异步 http 请求并在回调中设置它。我尝试在异步 http 调用之前设置它,然后在回调中添加项目。它工作得很好。我几分钟前刚刚解决了这个问题。谢谢你帮助我。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-01-30
  • 1970-01-01
  • 2016-11-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-05
相关资源
最近更新 更多