Android 二进制XML文件行#41:膨胀类片段时出错
日志中出现错误:pastebin.com/YLvmkAd4 碎片设置。类别:Android 二进制XML文件行#41:膨胀类片段时出错,android,android-fragments,Android,Android Fragments,日志中出现错误:pastebin.com/YLvmkAd4 碎片设置。类别: 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 an
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);
}
}
<?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
活动\u main.xml:
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);
}
}
<?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.javapastebin.com/a2NZLZFm
NavigationDrawerFragment.javapastebin.com/PqTMiPp3
fragment\u navigation\u drawer.xmlpastebin.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"/>
删除它,错误就会消失。现在,下一件事是让活动自己处理Drawerlayout
。因此,将所有抽屉代码转移到活动中,并忘记片段中的setup()方法
原因是因为您将片段声明为嵌入到活动中
,android会为您启动它,所以您不需要设置它
希望它能起作用好吧,你们都帮了我很多,但我自己修好了;) 我变了。
public class FragmentSettings extends PreferenceFragment {
public ListPreference mListPreference;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
@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);
}
}
public class FragmentSettings extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
到..
public class FragmentSettings extends PreferenceFragment {
public ListPreference mListPreference;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
@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);
}
}
public class FragmentSettings extends PreferenceFragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
}
}
并删除此
onCreateView
和mListPreference
:)希望这有助于其他人;) 将此行添加到styles.xml文件中
@style/PreferenceThemeOverlay
它在哪个版本的Android上崩溃了?我已经添加了我用过的设备。抱歉,忘了。看来你的碎片有问题。您是否在其他地方定义了碎片抽屉的id?我不认为这将是应用程序:布局部分…谢谢好的。我添加了所有出现的“碎片抽屉”。你的导航抽屉布局在哪里?我是android新手,不熟悉“充气”,但正在学习。:)对不起,先生,我的意思是通过删除app:layout来替换xml中的这个片段元素,明白吗?您已经在navi碎片的oncreatview中对其进行了充气,请转到充气机中要充气的碎片。充气,所以您只需复制此文件,以替换您的@8m47xYeah,这是迄今为止最简单的部分:D此处需要更改的内容:View View=充气机。充气(R.layout.fragment\u navigation\u drawer,container,false);代码>?无需更改,先生,这很好,也许您需要将最后一个参数更改为true。。我猜你的问题已经解决了还是?@8m47xNope。。没有任何变化:/