HoloEverywhere不适用于应用程序

时间:2012-10-26 14:04:28

标签: android-holo-everywhere

当我尝试在我的设置活动中使用HoloEverywhere时,我在logcat中收到此错误:

10-26 09:56:59.653: E/AndroidRuntime(3552): android.view.InflateException: Binary XML file line #2: Error inflating class <unknown>
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.LayoutInflater.createView(LayoutInflater.java:518)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at com.WazaBe.HoloEverywhere.LayoutInflater.onCreateView(LayoutInflater.java:195)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at com.WazaBe.HoloEverywhere.preference.Preference.onCreateView(Preference.java:514)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at com.WazaBe.HoloEverywhere.preference.Preference.getView(Preference.java:404)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at com.WazaBe.HoloEverywhere.preference.PreferenceGroupAdapter.getView(PreferenceGroupAdapter.java:158)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.AbsListView.obtainView(AbsListView.java:1430)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.ListView.makeAndAddView(ListView.java:1745)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.ListView.fillDown(ListView.java:670)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.ListView.fillFromTop(ListView.java:727)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.ListView.layoutChildren(ListView.java:1598)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.AbsListView.onLayout(AbsListView.java:1260)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.layout(View.java:7175)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.layout(View.java:7175)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.layoutHorizontal(LinearLayout.java:1243)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1049)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.layout(View.java:7175)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.layout(View.java:7175)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.layout(View.java:7175)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.layout(View.java:7175)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.layout(View.java:7175)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.layout(View.java:7175)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.ViewRoot.performTraversals(ViewRoot.java:1140)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1859)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.os.Handler.dispatchMessage(Handler.java:99)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.os.Looper.loop(Looper.java:130)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.app.ActivityThread.main(ActivityThread.java:3683)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at java.lang.reflect.Method.invokeNative(Native Method)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at java.lang.reflect.Method.invoke(Method.java:507)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at dalvik.system.NativeStart.main(Native Method)
10-26 09:56:59.653: E/AndroidRuntime(3552): Caused by: java.lang.reflect.InvocationTargetException
10-26 09:56:59.653: E/AndroidRuntime(3552):     at java.lang.reflect.Constructor.constructNative(Native Method)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at java.lang.reflect.Constructor.newInstance(Constructor.java:415)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.LayoutInflater.createView(LayoutInflater.java:505)
10-26 09:56:59.653: E/AndroidRuntime(3552):     ... 46 more
10-26 09:56:59.653: E/AndroidRuntime(3552): Caused by: java.lang.UnsupportedOperationException: Can't convert to dimension: type=0x2
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:463)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.<init>(View.java:2108)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.View.<init>(View.java:1899)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.view.ViewGroup.<init>(ViewGroup.java:286)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at android.widget.LinearLayout.<init>(LinearLayout.java:120)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at com.WazaBe.HoloEverywhere.widget.LinearLayout.<init>(LinearLayout.java:37)
10-26 09:56:59.653: E/AndroidRuntime(3552):     at com.WazaBe.HoloEverywhere.widget.LinearLayout.<init>(LinearLayout.java:33)
10-26 09:56:59.653: E/AndroidRuntime(3552):     ... 49 more

我从溢出菜单项开始我的settingsActivity。我可以在HoloEverywhere-Demo中添加一个溢出菜单,并在选择时启动我的活动并且它可以正常工作。这是我的设置活动:

public class SettingsActivity extends com.WazaBe.HoloEverywhere.sherlock.SPreferenceActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        addPreferencesFromResource(R.xml.settings);
    }   
    @Override
    public void onStart() {
        super.onStart();
        initActionBar();
    }

    @Override
    public void onResume() {
        super.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
    }

    @Override
    public void onStop() {
        super.onStop();
    }

    private void initActionBar() {
        ActionBar actionBar = getSupportActionBar();
        actionBar.setBackgroundDrawable(getResources().getDrawable(R.drawable.action_bar_gradient));
        actionBar.setTitle(R.string.settings);
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setDisplayUseLogoEnabled(true);
    }
}

为什么我可以在演示中使用此活动没有任何问题的任何想法,但当我添加到我的应用程序时,我收到我发布的错误?

1 个答案:

答案 0 :(得分:3)

您的settings.xml是否使用holo属性?你必须将xmlns更改为holo,并将所有android:更改为holo:

像这样:

<PreferenceScreen xmlns:holo="http://schemas.android.com/apk/res-auto" >

<PreferenceCategory holo:title="title" >
    <Preference
        holo:key="key"
        holo:summary="summary"
        holo:title="title" />
</PreferenceCategory>

<Preference
    holo:key="key"
    holo:title="title"
    holo:selectable="true" />
</PreferenceScreen>