Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify Layout Top margin for overlay action bar

I am following the tutorial about

Overlaying the Action Bar

When I tried to add

<!-- activity_main.xml in layout folder -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:paddingTop="@dimen/activity_action_bar_overlay_margin">

<!-- dimens.xml in values folder -->
<dimen name="activity_action_bar_overlay_margin">?attr/actionBarSize</dimen>

and then I got the following errors:

01-25 23:10:33.132: E/AndroidRuntime(554): FATAL EXCEPTION: main
01-25 23:10:33.132: E/AndroidRuntime(554): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.myfirstapp/com.example.myfirstapp.MainActivity}: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1956)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1981)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.app.ActivityThread.access$600(ActivityThread.java:123)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1147)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.os.Handler.dispatchMessage(Handler.java:99)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.os.Looper.loop(Looper.java:137)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.app.ActivityThread.main(ActivityThread.java:4424)
01-25 23:10:33.132: E/AndroidRuntime(554):  at java.lang.reflect.Method.invokeNative(Native Method)
01-25 23:10:33.132: E/AndroidRuntime(554):  at java.lang.reflect.Method.invoke(Method.java:511)
01-25 23:10:33.132: E/AndroidRuntime(554):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:784)
01-25 23:10:33.132: E/AndroidRuntime(554):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)
01-25 23:10:33.132: E/AndroidRuntime(554):  at dalvik.system.NativeStart.main(Native Method)
01-25 23:10:33.132: E/AndroidRuntime(554): Caused by: android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.view.LayoutInflater.createView(LayoutInflater.java:606)
01-25 23:10:33.132: E/AndroidRuntime(554):  at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.view.LayoutInflater.onCreateView(LayoutInflater.java:653)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:678)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.view.LayoutInflater.inflate(LayoutInflater.java:466)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
01-25 23:10:33.132: E/AndroidRuntime(554):  at com.android.internal.policy.impl.PhoneWindow.setContentView(PhoneWindow.java:251)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.app.Activity.setContentView(Activity.java:1835)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.support.v7.app.ActionBarActivity.superSetContentView(ActionBarActivity.java:216)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.support.v7.app.ActionBarActivityDelegateICS.setContentView(ActionBarActivityDelegateICS.java:111)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.support.v7.app.ActionBarActivity.setContentView(ActionBarActivity.java:76)
01-25 23:10:33.132: E/AndroidRuntime(554):  at com.example.myfirstapp.MainActivity.onCreate(MainActivity.java:19)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.app.Activity.performCreate(Activity.java:4465)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1920)
01-25 23:10:33.132: E/AndroidRuntime(554):  ... 11 more
01-25 23:10:33.132: E/AndroidRuntime(554): Caused by: java.lang.reflect.InvocationTargetException
01-25 23:10:33.132: E/AndroidRuntime(554):  at java.lang.reflect.Constructor.constructNative(Native Method)
01-25 23:10:33.132: E/AndroidRuntime(554):  at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.view.LayoutInflater.createView(LayoutInflater.java:586)
01-25 23:10:33.132: E/AndroidRuntime(554):  ... 26 more
01-25 23:10:33.132: E/AndroidRuntime(554): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.view.View.<init>(View.java:2794)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.view.ViewGroup.<init>(ViewGroup.java:385)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.widget.LinearLayout.<init>(LinearLayout.java:174)
01-25 23:10:33.132: E/AndroidRuntime(554):  at android.widget.LinearLayout.<init>(LinearLayout.java:170)
01-25 23:10:33.132: E/AndroidRuntime(554):  ... 29 more

I am wondering do i have to use RelativeLayout in order to use ?android:attr/actionBarSize, what does the effect actually look like? and how to get a transparent action bar?

cheers

like image 297
daiyue Avatar asked Jan 25 '14 23:01

daiyue


1 Answers

Your formatting is wrong, it should be:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:paddingTop="?attr/actionBarSize">

You should define dimensions in dimens.xml, not inside the layout.

like image 131
Emmanuel Avatar answered Nov 15 '22 00:11

Emmanuel