片段中工具栏上方显示额外空间。如何删除工具栏上方的额外空间?

4

我尝试在活动中加载片段。但是工具栏上方有更多的空间?

这里我提供了我在应用程序中尝试的内容。没有片段活动打开得很好

样式:

 <!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:windowEnableSplitTouch">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowBackground">@android:color/white</item>
</style>

activity_home.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=".home.HomeActivity">

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

<FrameLayout
    android:id="@+id/fragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>

enter image description here


默认情况下,Android 的基本活动中定义了弹出主题。 - Naveen Kumar M
在清单文件中为您的活动设置无操作栏主题。 - Naveen Shriyan
然后将其放入清单(manifest)而不是工具栏(Toolbar)。 - Janki Gadhiya
不,它没有起作用。我认为可能是Bottombar出了问题。参考:http://androidgifts.com/build-android-material-design-bottom-navigation/ - Naveen Kumar M
是的,上述问题属于Bottombar库。 我已经解决了。 https://github.com/roughike/BottomBar/issues/61 - Naveen Kumar M
显示剩余5条评论
1个回答

3
尝试如下更改,并相应地设置您的布局..
<?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=".home.HomeActivity">

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

<FrameLayout
    android:id="@+id/fragmentContainer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout>
 <style name="AppTheme" parent="Theme.AppCompat.Light">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>
    <item name="windowActionBar">false</item>
    <item name="windowNoTitle">true</item>
    <item name="windowActionModeOverlay">true</item>
    <item name="android:windowEnableSplitTouch">false</item>
    <item name="android:windowContentOverlay">@null</item>
    <item name="android:windowBackground">@android:color/white</item>
</style>

<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />

以下是Manifest应用程序标签:

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".home.HomeActivity">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

1
please mention your changes. - Amit Vaghela
@NaveenKumarM:我已经更新了我的答案,它在我的端上完全可行。请告诉我它是否在你的端上工作。 - Tejas
我移除了两种样式。我按照你提到的复制,但它没有起作用。 - Naveen Kumar M
@NaveenKumarM:现在请查看我的完整更新答案,它一定可以正常工作,因为我也在我的端上进行了测试。如果问题仍然存在,可能是您的状态栏空间出了问题。 - Tejas
@Tez 你应该解释一下你在答案中所做的任何更改。 - Jay Rathod
显示剩余5条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接