Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.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
Android 子活动中未显示工具栏_Android_Android Layout_Layout_Android Toolbar - Fatal编程技术网

Android 子活动中未显示工具栏

Android 子活动中未显示工具栏,android,android-layout,layout,android-toolbar,Android,Android Layout,Layout,Android Toolbar,我正在为所有活动设计一个导航抽屉,所以我想在BaseActivity中添加它,然后在需要导航抽屉的其他活动中继承它,我确实成功地让导航抽屉工作了,但由于某种原因,工具栏没有显示在继承BaseActivity的子活动中,我尝试了很多方法,并在堆栈溢出问题上签出了很多问题,但我无法真正找出问题所在 下面是代码:布局文件 activity_base.xml 然后我在其他子活动(HomeActivity)中继承此活动: HomeActivity的xml文件: <LinearLayout xmlns

我正在为所有活动设计一个导航抽屉,所以我想在BaseActivity中添加它,然后在需要导航抽屉的其他活动中继承它,我确实成功地让导航抽屉工作了,但由于某种原因,工具栏没有显示在继承BaseActivity的子活动中,我尝试了很多方法,并在堆栈溢出问题上签出了很多问题,但我无法真正找出问题所在

下面是代码:布局文件

activity_base.xml

然后我在其他子活动(HomeActivity)中继承此活动:

HomeActivity的xml文件:

<LinearLayout 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/home_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="app.packman.activity.HomeActivity">

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.TabLayout
            android:id="@+id/home_tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <include layout="@layout/content_home" />
<!-- other content of activity-->
</android.support.design.widget.CoordinatorLayout>

任何建议都会有很大帮助

您可以尝试添加

app:layout_behavior="@string/appbar_scrolling_view_behavior"
在框架布局中

public class HomeActivity extends BaseActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //setContentView(R.layout.activity_home);
    ViewGroup content = (ViewGroup) findViewById(R.id.content_frame);
    getLayoutInflater().inflate(R.layout.activity_home, content, true);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
}
<LinearLayout 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/home_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context="app.packman.activity.HomeActivity">

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.design.widget.TabLayout
            android:id="@+id/home_tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

    <include layout="@layout/content_home" />
<!-- other content of activity-->
</android.support.design.widget.CoordinatorLayout>
app:layout_behavior="@string/appbar_scrolling_view_behavior"