FrameLayout创建另一个ActionBar

时间:2015-06-15 15:26:34

标签: android android-actionbar android-framelayout

我有一个ActionBar,在某些活动中显示。 不幸的是,在其中一个中,我使用了FrameLayout,FrameLayout创建了另一个ActionBar。如何删除第二个ActionBar?

贝娄,布局:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:orientation="vertical"
    android:layout_height="match_parent">

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

<android.support.v4.widget.DrawerLayout
        android:layout_width="match_parent"
        android:id="@+id/browser_drawer_layout"
        android:layout_height="match_parent">

    <!-- activity view -->
    <FrameLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/content_frame">

        <LinearLayout
                xmlns:android="http://schemas.android.com/apk/res/android"
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            <Button
                    android:id="@+id/buttonFindSelected"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="@string/selection" />

            <ListView
                    android:id="@android:id/list"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent" />
        </LinearLayout>
    </FrameLayout>

    <!-- navigation drawer -->
    <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="start"
            android:background="?attr/colorPrimaryDark">

        <ListView
                android:id="@+id/browser_left_drawer"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:choiceMode="singleChoice"/>
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

DrawerLayout工具栏的代码:

<android.support.v7.widget.Toolbar
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="?attr/colorPrimary"/>

我的主题:

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base"/>

<style name="AppTheme.Base" parent="Theme.AppCompat.NoActionBar">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="drawerArrowStyle">@style/DrawerArrowStyle</item>
</style>

<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">
    <item name="spinBars">true</item>
    <item name="color">@android:color/white</item>
</style>

我的主题(适用于api 21 +)

<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="AppTheme.Base">
    <item name="android:windowContentTransitions">true</item>
    <item name="android:windowAllowEnterTransitionOverlap">true</item>
    <item name="android:windowAllowReturnTransitionOverlap">true</item>
    <item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
    <item name="android:windowSharedElementExitTransition">@android:transition/move</item>
</style>

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

问题解决了......

我以错误的方式使用FragmentManager。结果是我的一些元素重复。 这里有更多信息(第二个答案):http://www.codedisqus.com/0zmgWXjjXj/android-fragment-duplicate-objects-in-layout.html