8

Android 2.2 プロジェクトで Fragments と ActionBar を使用しようとしています。「?android:attr/actionBarSize」を使用するとエラーが発生します。その値を正しく取得および設定するにはどうすればよいですか?

例:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/frags">

    <fragment class="com.example.android.hcgallery.TitlesFragment"
            android:id="@+id/frag_title"
            android:visibility="gone"
            android:layout_marginTop="?android:attr/actionBarSize"
            android:layout_width="@dimen/titles_size"
            android:layout_height="match_parent" />

    <fragment class="com.example.android.hcgallery.ContentFragment"
            android:id="@+id/frag_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

</LinearLayout>

エラー: 指定された名前 (「layout_marginTop」で値「?android:attr/actionBarSize」) に一致するリソースが見つかりませんでした。

4

2 に答える 2

16

あなたはただ使うべきです:

android:layout_marginTop="?attr/actionBarSize"

http://developer.android.com/training/basics/actionbar/overlaying.htmlを参照してください。

「... android: プレフィックスが付いたものは、プラットフォームにスタイルを含む Android のバージョン用であり、プレフィックスのないものは、サポート ライブラリからスタイルを読み取る古いバージョン用です...」

交換する私にとって

android:layout_marginTop="?android:attr/actionBarSize" 

android:layout_marginTop="?attr/actionBarSize" 

Android 2.2 および Android 4.3 でアプリを問題なく起動するのに役立ちました。

于 2014-01-28T18:59:51.187 に答える
2

問題は、アクションバーがandroid 3.0に付属していて、2.2を使用していることだと思います。しかし、「actionbarsherlock」と呼ばれる拡張機能によってこれをスキップする方法があります。

于 2011-12-30T18:39:38.013 に答える