如何获得"安卓?ATTR / actionBarSize"与兼容库

如何获得"安卓?ATTR / actionBarSize"与兼容库

问题描述:

我试图使用片段和动作条在Android 2.2的项目。目前在使用一些错误?机器人:ATTR / actionBarSize?,如何获得并正确设置值

I'm trying to use Fragments and ActionBar in a Android 2.2 project. There is some error when using "?android:attr/actionBarSize", how to get and set that value correctly?

例如:

<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,值为机器人:ATTR / actionBarSize)。

您应该只使用:

android:layout_marginTop="?attr/actionBarSize"

请参阅http://developer.android.com/training/basics/actionbar/overlaying.html

......一个与Android的:preFIX是Android的版本   包括的样式在平台和所述一个无preFIX是   旧版本的读取支持库的风格......

"...The one with the android: prefix is for versions of Android that include the style in the platform and the one without the prefix is for older versions that read the style from the Support Library..."

有关我更换

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

android:layout_marginTop="?attr/actionBarSize" 

帮助发起在Android 2.2和Android 4.3的应用程序没有任何问题。

helped to launch app on Android 2.2 and Android 4.3 without any issues.