2

ナビゲーション ドロワーでツールバー (android.support.v7.widget.Toolbar) を使用しようとしています。ただし、例外「クラス android.support.v7.widget.Toolbar の拡張エラー」が表示されます。android.support.v7.widget.Toolbarxml で使用しない場合、コードは正常に機能します。私の活動は伸びてandroid.support.v7.app.ActionBarActivityいます。ここに私のmain_activity.xmlがあります

    <!--
         As the main content view, the view below consumes the entire
         space available using match_parent in both dimensions.

    -->

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


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

        <!-- We use a Toolbar so that our drawer can be displayed
             in front of the action bar -->
        <android.support.v7.widget.Toolbar  
            android:id="@+id/my_awesome_toolbar"
            android:layout_height="wrap_content"
            android:layout_width="match_parent"
            android:minHeight="?attr/actionBarSize"
            android:background="?attr/colorPrimary" />


    </LinearLayout>

        </FrameLayout>

    <!--
         android:layout_gravity="start" tells DrawerLayout to treat
         this as a sliding drawer on the left side for left-to-right
         languages and on the right side for right-to-left languages.
         If you're not building against API 17 or higher, use
         android:layout_gravity="left" instead.
    -->
    <!--
         The drawer is given a fixed width in dp and extends the full height of
         the container.
    -->

    <fragment
        android:id="@+id/navigation_drawer"
        class="com.jooleh.android.merchant.NavigationDrawerFragment"
        android:layout_width="300dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        tools:layout="@layout/fragment_navigation_drawer" />

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

Styles.xml

 <style name="AppBaseTheme" parent="Theme.AppCompat">
        <item name="colorPrimary">@color/red_primary_500</item>
        <item name="colorPrimaryDark">@color/red_primary_700</item>
        <item name="colorAccent">@color/green_secondary</item>
        <item name="windowActionBar">false</item>

    </style>

スタイル-v11

<style name="AppBaseTheme" parent="Theme.AppCompat">
        <!-- API 11 theme customizations can go here. -->
        <item name="windowActionBar">false</item>
    </style>

スタイル-v14

<style name="AppBaseTheme" parent="Theme.AppCompat">
        <!-- API 14 theme customizations can go here. -->
        <item name="windowActionBar">false</item>
    </style>

私はジェリービーン、minSdkVersion="16" および targetSdkVersion="21" でテストしています。

4

2 に答える 2

3

以下を置き換えることで、この問題を解決できました。

ツールバー レイアウトで、以下を置き換えます。

android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"

android:minHeight="@dimen/abc_action_bar_default_height_material"
android:background="@color/myColor"
于 2014-11-13T09:07:48.930 に答える
1

遅いかもしれませんが、誰かの役に立ちます。私は同じ問題に苦労しましたが、それから変更しました

android.support.v7.widget.ツールバー

android.widget.ツールバー

うまくいきましたが、理由はわかりません。誰かが洞察を持っている場合は、共有してください

于 2015-09-22T22:30:36.587 に答える