如何获得"安卓?ATTR / actionBarSize"与兼容库 [英] How to get "?android:attr/actionBarSize" with Compatibility Library

查看:1018
本文介绍了如何获得"安卓?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"

请参阅<一href="http://developer.android.com/training/basics/actionbar/overlaying.html">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.

这篇关于如何获得&QUOT;安卓?ATTR / actionBarSize&QUOT;与兼容库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆