1

我在我的应用程序中使用 DrawerNavigator。我创建了一个与 android 4.2 完美配合的 android 应用程序,但是当我尝试在 android 2.2 中启动它时出现此错误:

android.view.InflateException: Binary XML file line #1: Error inflating class <unknown>
at android.view.LayoutInflater.createView(LayoutInflater.java:518)
at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:568)
at android.view.LayoutInflater.inflate(LayoutInflater.java:386)
at android.view.LayoutInflater.inflate(LayoutInflater.java:320)
at android.widget.ArrayAdapter.createViewFromResource(ArrayAdapter.java:332)
at android.widget.ArrayAdapter.getView(ArrayAdapter.java:323)
at android.widget.AbsListView.obtainView(AbsListView.java:1582)
at android.widget.ListView.makeAndAddView(ListView.java:1801)
at android.widget.ListView.fillDown(ListView.java:724)
at android.widget.ListView.fillFromTop(ListView.java:781)
at android.widget.ListView.layoutChildren(ListView.java:1638)
at android.widget.AbsListView.onLayout(AbsListView.java:1412)
at android.view.View.layout(View.java:7175)
at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:672)
at android.view.View.layout(View.java:7175)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7175)
at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1254)
at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1130)
at android.widget.LinearLayout.onLayout(LinearLayout.java:1047)
at android.view.View.layout(View.java:7175)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7175)
at android.widget.FrameLayout.onLayout(FrameLayout.java:338)
at android.view.View.layout(View.java:7175)
at android.view.ViewRoot.performTraversals(ViewRoot.java:1146)
at android.view.ViewRoot.handleMessage(ViewRoot.java:1866)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:130)
at android.app.ActivityThread.main(ActivityThread.java:3687)

编辑:这些行也在那里:

07-22 16:00:52.111: E/AndroidRuntime(470): Caused by: android.content.res.Resources$NotFoundException: File res/color/abs__primary_text_holo_light.xml from xml type drawable resource ID #0x0
07-22 16:00:52.111: E/AndroidRuntime(470):  at android.content.res.Resources.loadXmlResourceParser(Resources.java:1924)
07-22 16:00:52.111: E/AndroidRuntime(470):  at android.content.res.Resources.loadDrawable(Resources.java:1692)
07-22 16:00:52.111: E/AndroidRuntime(470):  ... 42 more

我不知道为什么。我打电话给我的fragment( ShelrockFragment) 从MainActivity

FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.content_frame, newsMasterFragment, "MasterFragment");
        bundle.putBoolean("onFirstRow", true);
        newsMasterFragment.setArguments(bundle);

膨胀视图时它会崩溃:

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_news_master,
            container, false);
4

3 回答 3

7

如果有人有同样的问题,问题是android:background

android:background="?android:attr/activatedBackgroundIndicator"

粉碎了整个应用程序。所以我在蜂窝之前的版本中删除了它

于 2013-07-23T09:51:42.857 回答
0

这是因为 Fragments API 是在 Android 3.0(API 级别 11)中引入的。

如果要在 Android 2.2(API 级别 8)中使用它们,则必须使用 Google 提供的兼容性库。如何做到这一点,您可以在此处阅读示例:Android 2.2.1、2.3、2.0 中的片段。这可能吗?

于 2013-07-22T13:44:02.223 回答
0

在drawer_list_item.xml 文件中

删除 android:background="?android:attr/activatedBackgroundIndicator" 行

如果你想用 html 颜色代码改变背景。

于 2013-12-10T10:19:51.310 回答