How to get "?android:attr/actionBarSize" with Compatibility Library
Asked Answered
M

2

8

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?

Example:

<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>

Error: No resource found that matches the given name (at 'layout_marginTop' with value '?android:attr/actionBarSize').

Minimal answered 13/10, 2011 at 21:47 Comment(1)
did you found the solution for this? thanks mate!Hensley
D
16

You should just use:

android:layout_marginTop="?attr/actionBarSize"

See 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..."

For me replacing

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

with

android:layout_marginTop="?attr/actionBarSize" 

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

Dannielledannon answered 28/1, 2014 at 18:59 Comment(0)
S
2

I think the problem is that actionbar comes with android 3.0 and you are using 2.2. But there is a way to skip this by a extension called "actionbarsherlock".

Syndrome answered 30/12, 2011 at 18:39 Comment(1)
So, what did you do to fix the problem? Always answer your questions if you found the answer. It may come handy for future users.Cheatham

© 2022 - 2024 — McMap. All rights reserved.