如何防止操作栏被切断? [英] How can I prevent the action bar from being cut off?
问题描述
将手机升级到棉花糖后,我制作的所有应用程序的操作栏都将被切断.该应用程序可以在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
<item name="android:fitsSystemWindows">true</item>
这篇关于如何防止操作栏被切断?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!