gpt4 book ai didi

android - 二进制 XML 文件行 #41 : Error inflating class fragment

转载 作者:行者123 更新时间:2023-11-29 01:32:13 25 4
gpt4 key购买 nike

日志错误 pastebin.com/YLvmkAd4

FragmentSettings.class:

package com.android.app;

import android.os.Bundle;
import android.preference.ListPreference;
import android.preference.PreferenceFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class FragmentSettings extends PreferenceFragment {

[..]

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

mListPreference = (ListPreference) getPreferenceManager().findPreference("preference_key");

return inflater.inflate(R.layout.activity_main, container, false);
}
}

activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer"
android:layout_width="match_parent"
android:fitsSystemWindows="true"
android:layout_height="match_parent">

<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<include
android:id="@+id/toolbar_actionbar"
layout="@layout/toolbar_default"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:clickable="true"
android:layout_height="match_parent">
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</FrameLayout>
</LinearLayout>
<!-- android:layout_marginTop="?android:attr/actionBarSize"-->
<com.android.app.ScrimInsetsFrameLayout
android:id="@+id/scrimInsetsFrameLayout"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:layout_gravity="start"
app:insetForeground="#4000"
android:elevation="10dp">

<fragment
android:id="@+id/fragment_drawer"
android:name="com.android.app.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:layout="@layout/fragment_navigation_drawer" />
</com.android.app.ScrimInsetsFrameLayout>


</android.support.v4.widget.DrawerLayout>

设备:

Oppo N1, Android 4.2.2
Samsung Galaxy Note 1, Android 5.1.1

我已经为这个错误花费了好几个小时,却找不到它。线索是完全相同的应用程序在 Android 5.1.1 上完美运行。

附加:

MainActivity.java pastebin.com/a2NZLZFm

NavigationDrawerFragment.java pastebin.com/PqTMiPp3

fragment_navigation_drawer.xml pastebin.com/eVeAdv17

最佳答案

<fragment
android:id="@+id/fragment_drawer"
android:name="com.android.app.NavigationDrawerFragment"
android:layout_width="@dimen/navigation_drawer_width"
android:layout_height="match_parent"
android:fitsSystemWindows="true"/>

而是使用它,并在你的 onCreateView() 中膨胀布局 android 将负责添加它 ViewGroup/window 等等

这是您的 MainActivity 中的这一行

 // Set up the drawer.
mNavigationDrawerFragment.setup(R.id.fragment_drawer,
(DrawerLayout) findViewById(R.id.drawer), mToolbar);

删除它,错误就会消失。接下来就是让 Activity 自己处理 Drawerlayout。所以将所有抽屉代码转移到您的 Activity 中并忘记 fragment 中的 setup() 方法

因为你在Activity中声明了嵌入的fragment,android会为你启动它,所以你不需要设置

希望它有用

关于android - 二进制 XML 文件行 #41 : Error inflating class fragment,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30552523/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com