与片段的透明工具栏背景在它后

时间:2016-04-06 17:28:42

标签: android android-fragments android-toolbar

处理我不应该包含ToolBar的片段(那些将由Activity处理)和一些包括工具栏的情况的最佳方法是什么?我知道如何使其透明,但是如何创建一个可以轻松模块化以处理这两种情况的模板?

对于特定的片段我想要一个透明的工具栏,片段内容部分位于工具栏后面,如下所示:enter image description here

我试图让另一个FrameLayout覆盖所有屏幕,然后由FragmentTransaction替换,但没有任何反应......

    <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activityv2.ActivityHome">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:orientation="vertical">

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

        <FrameLayout
            android:id="@+id/content_frame"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/left_drawer_item"
        android:layout_width="200dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:alpha="0.92"
        android:background="@color/gray_very_dark"
        android:orientation="vertical">



    </LinearLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/full_content_frame"
        android:background="@color/dark_red"
        android:fitsSystemWindows="true"/>

</android.support.v4.widget.DrawerLayout>

对于不需要工具栏的片段,我替换FrameLayout“content_frame”,对于需要隐藏ToolBar的片段,我替换“full_content_Frame”。对于第二个,当我更换它时没有任何反应。以下是替换片段的代码:

private void selectProfilFragment() {
    BackHandledFragment fragment = new FragmentUserProfil();
    setSelectedFragment(fragment);
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    ft.setCustomAnimations(R.anim.pull_in_right, R.anim.push_out_left, R.anim.pull_in_left, R.anim.push_out_right);
    ft.replace(R.id.full_content_frame, fragment)
            .addToBackStack(fragment.getTagText())
            .commit();

    setTitle("Profil");
    mDrawerLayout.closeDrawer(mDrawerLinear);
}

0 个答案:

没有答案
相关问题