我正在尝试在 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>
错误:找不到与给定名称匹配的资源(在值为“?android:attr/actionBarSize”的“layout_marginTop”处)。
最佳答案
你应该只使用:
android:layout_marginTop="?attr/actionBarSize"
参见 http://developer.android.com/training/basics/actionbar/overlaying.html
"...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 上顺利启动应用程序。
关于android - 如何使用兼容性库获取 "?android:attr/actionBarSize",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7760817/