如何防止操作栏被切断? [英] How can I prevent the action bar from being cut off?

查看:29
本文介绍了如何防止操作栏被切断?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我将手机升级到 Marshmallow 后,我制作的所有应用的操作栏都被切断了.该应用在 Lollipop 和 Kitkat 上运行良好.

All the apps that I have made have their actionbar cut off after I upgraded my phone to Marshmallow. The app works fine on Lollipop and Kitkat.

该应用基本上只有一个视图,但在我更新后的手机上无法正常显示.

The app basically has one view, and it doesn't show up properly on my updated phone.

上半部分切掉
activity_main.xml

Top half cut off
activity_main.xml

<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="com.shalin.clickme.MainActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    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>

<include layout="@layout/content_main" />

<android.support.design.widget.FloatingActionButton
    android:id="@+id/fab"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="bottom|end"
    android:layout_margin="@dimen/fab_margin"
    android:src="@android:drawable/ic_dialog_email" />

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


content_main.xml


content_main.xml

<RelativeLayout 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:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.shalin.clickme.MainActivity">

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Click Me"
    android:onClick="switchButtons"
    android:id="@+id/button1"
    android:layout_alignParentTop="true"
    android:layout_alignParentStart="true" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/button2"
    android:text=""
    android:onClick="switchButtons"
    android:layout_alignBottom="@+id/button1"
    android:layout_alignParentEnd="true" />
</RelativeLayout>

我尝试了 android:fitsSystemWindows,这就是我得到的:使用 android:fitsSystemWindows

I tried the android:fitsSystemWindows, and this is what I get: With android:fitsSystemWindows

推荐答案

在您的根视图中使用 android:fitsSystemWindows="true"布局.

android:fitsSystemWindows 是一个内部属性,根据状态栏等系统窗口调整视图布局.如果为 true,则调整此视图的填充为系统窗口留出空间.仅当此视图在非嵌入式活动中时才会生效.

And an android:fitsSystemWindows is an internal attribute to adjust view layout based on system windows such as the status bar. If true, adjusts the padding of this view to leave space for the system windows. Will only take effect if this view is in a non-embedded activity.

并且您也可以通过在style.xml主题中将其设置为

and also you can set it globally by setting in the style.xml theme as

true

这篇关于如何防止操作栏被切断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆