Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 工具栏和状态栏之间的空白_Java_Android_Android Toolbar - Fatal编程技术网

Java 工具栏和状态栏之间的空白

Java 工具栏和状态栏之间的空白,java,android,android-toolbar,Java,Android,Android Toolbar,只需知道图像中的listview是片段生成的。但我不认为这会干扰工具栏的布局。以下是布局代码- <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:i

只需知道图像中的listview是片段生成的。但我不认为这会干扰工具栏的布局。以下是布局代码-

    <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:id="@+id/fragment_songlistview"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/croctooth"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    tools:context="com.shaikhsakib.sounddemo.SongActivity">


    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@color/colorPrimary"
        android:minHeight="?attr/actionBarSize"
        app:theme="@style/ThemeOverlay.AppCompat.Dark"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        />

    <ListView
        android:id="@+id/fragmentSongListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar2" />
</RelativeLayout>
    package com.shaikhsakib.sounddemo;

import android.app.ActionBar;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

public class SongActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_song);

        loadFragment();
        Toolbar toolbar2 = (Toolbar) findViewById(R.id.toolbar2);
        setSupportActionBar(toolbar2);

    }

    private void loadFragment() {
// create a FragmentManager
        FragmentManager fm;
        fm = getFragmentManager();
// create a FragmentTransaction to begin the transaction and replace the Fragment
        FragmentTransaction fragmentTransaction = fm.beginTransaction();
// replace the FrameLayout with new Fragment
        SongListFragment slv = new SongListFragment();
        fragmentTransaction.replace(R.id.songFrameLayout, slv);
        fragmentTransaction.commit(); // save the changes
    }
}
我检查了大多数关于堆栈溢出的空白工具栏相关答案,但没有任何结果。也许我的问题不同

编辑1

这是我的主要活动。它还将片段listview加载到ha自定义工具栏中。但这里没有这样的空白-

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    loadFragment();
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

setSupportActionBar(toolbar);

}

private void loadFragment() {
// create a FragmentManager
        FragmentManager fm;
        fm = getFragmentManager();
// create a FragmentTransaction to begin the transaction and replace the Fragment
        FragmentTransaction fragmentTransaction = fm.beginTransaction();
// replace the FrameLayout with new Fragment
        PLayListFragment flv = new PLayListFragment();
        fragmentTransaction.replace(R.id.frameLayout, flv);
        fragmentTransaction.commit(); // save the changes
    }
}

还请注意,我正在两个活动中替换相同的R.id.frameLayout,但这与工具栏无关。有人能告诉我为什么它不是发生在MainActivity中,而是发生在其他activity中。

问题实际上不是工具栏,而是状态栏。它需要协调的布局,而不是作为父对象的相对布局。因此,我所要做的就是作为CoordinatorLayout的子级创建相对布局,并传递一个属性,如android:fitsystemwindows=“true”。这就解决了问题

以下是解决方案-

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:tools="http://schemas.android.com/tools"
    android:fitsSystemWindows="true"
    android:background="@color/croctooth"
    android:theme="@style/Theme.AppCompat.Light.NoActionBar"
    tools:context="com.shaikhsakib.sounddemo.SongActivity">
<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@color/colorPrimary"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
        />

    <ListView
        android:id="@+id/fragmentSongListView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@+id/toolbar2" />


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


croctooth的颜色是什么?是灰色吗?请分享您的主要活动布局。将相对布局设置为线性布局,以删除“android:minHeight=“?attr/actionBarSize”。我想这可能就是原因@sakibyes鳄齿为浅灰色。把主要活动都放了。没有相对的layput不能解决问题,删除android:minHeight=“?attr/actionBarSize”也不能解决问题。