- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我正在尝试一个实验,这是第一次不使用 AppCompatActivity
并使用新的 Material 主题。我不需要也不希望在这个特定的应用程序中实现向后兼容性,因此我正在构建 Marshmallow。
目的是让初始 Activity 有一个 actionbar
,左侧有导航菜单,就像在 AppCompat
中正常工作一样。但是,在将基本主题设置为不再使用 AppCompat
主题、更改布局并尝试启动主要 Activity 后,在 Activity 的 之后发生
方法完成。异常发生在内部类 IndexOutOfBoundsException
onCreate()android.support.design.internal.NavigationMenuItemView
的初始化期间。
无论 NavigationView
和相关菜单是在 XML 中定义还是以编程方式添加,都会发生相同的异常。所以我很确定任何问题都与新的 Material 主题有关,而不是使用 AppCompat
东西。
还有其他人遇到过这个吗?这应该有效,还是我只是愚蠢?
以下是一些 fragment :删除了几乎所有自定义项的应用样式:
<style name="AppTheme" parent="android:Theme.Material.Light">
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
activity_main 布局文件:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<include layout="@layout/app_bar_main"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<!-- comment Nav view out and activity starts fine, with no menu of course -->
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:menu="@menu/activity_main_drawer" />
</android.support.v4.widget.DrawerLayout>
示例主要 Activity 代码:
public class MainActivity extends Activity
implements NavigationView.OnNavigationItemSelectedListener {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
toggle.syncState();
/* uncomment this if XML has its view def removed, same exception results either way
NavigationView navigationView = new NavigationView(this);
navigationView.setNavigationItemSelectedListener(this);
navigationView.setLayoutParams(new DrawerLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.START));
navigationView.setFitsSystemWindows(true);
navigationView.inflateMenu(R.menu.activity_main_drawer);
drawer.addView(navigationView);
*/
}
...
我调试了 View.java
代码和相关的 TypedArray
代码,可以看到它在构建内部菜单项类时尝试处理属性失败的地方。它闻起来像一个错误,但这是我第一次尝试不使用 AppCompat
主题和 AppCompatActivity
。我也试过使用这个主题的 NoActionBar
变体并添加我自己的工具栏,但这没有区别,同样的错误。
有什么想法/想法吗?提前致谢。让我知道我是否遗漏了有用的信息,我是个新手
最后,这是巨大的调用堆栈。根本原因是堆栈中的第三个异常:
06-10 14:49:53.763 30675-30675/test E/Cause: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView
android.view.InflateException: Binary XML file line #17: Error inflating class android.support.design.internal.NavigationMenuItemView
at android.view.LayoutInflater.createView(LayoutInflater.java:645)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.support.design.internal.NavigationMenuPresenter$NormalViewHolder.<init>(NavigationMenuPresenter.java:278)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:379)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:328)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2625)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.design.widget.NavigationView.onMeasure(NavigationView.java:223)
at android.view.View.measure(View.java:18794)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1104)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:446)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18794)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-10 14:49:55.023 30675-30675/test E/Cause: null
java.lang.reflect.InvocationTargetException
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.support.design.internal.NavigationMenuPresenter$NormalViewHolder.<init>(NavigationMenuPresenter.java:278)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:379)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:328)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2625)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.design.widget.NavigationView.onMeasure(NavigationView.java:223)
at android.view.View.measure(View.java:18794)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1104)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:446)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18794)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:844)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
06-10 14:49:56.083 30675-30675/test E/Cause: length=522; index=540
java.lang.ArrayIndexOutOfBoundsException: length=522; index=540
at android.content.res.TypedArray.getValueAt(TypedArray.java:1132)
at android.content.res.TypedArray.getDimensionPixelSize(TypedArray.java:661)
at android.view.View.<init>(View.java:3964)
at android.view.ViewGroup.<init>(ViewGroup.java:573)
at android.view.ViewGroup.<init>(ViewGroup.java:569)
at android.support.v7.widget.LinearLayoutCompat.<init>(LinearLayoutCompat.java:148)
at android.support.design.internal.ForegroundLinearLayout.<init>(ForegroundLinearLayout.java:56)
at android.support.design.internal.NavigationMenuItemView.<init>(NavigationMenuItemView.java:64)
at android.support.design.internal.NavigationMenuItemView.<init>(NavigationMenuItemView.java:60)
at java.lang.reflect.Constructor.newInstance(Native Method)
at android.view.LayoutInflater.createView(LayoutInflater.java:619)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:764)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:704)
at android.view.LayoutInflater.inflate(LayoutInflater.java:492)
at android.view.LayoutInflater.inflate(LayoutInflater.java:423)
at android.support.design.internal.NavigationMenuPresenter$NormalViewHolder.<init>(NavigationMenuPresenter.java:278)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:379)
at android.support.design.internal.NavigationMenuPresenter$NavigationMenuAdapter.onCreateViewHolder(NavigationMenuPresenter.java:328)
at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:5482)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4707)
at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:4617)
at android.support.v7.widget.LinearLayoutManager$LayoutState.next(LinearLayoutManager.java:1994)
at android.support.v7.widget.LinearLayoutManager.layoutChunk(LinearLayoutManager.java:1390)
at android.support.v7.widget.LinearLayoutManager.fill(LinearLayoutManager.java:1353)
at android.support.v7.widget.LinearLayoutManager.onLayoutChildren(LinearLayoutManager.java:574)
at android.support.v7.widget.RecyclerView.dispatchLayoutStep2(RecyclerView.java:3028)
at android.support.v7.widget.RecyclerView.onMeasure(RecyclerView.java:2625)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.support.design.widget.NavigationView.onMeasure(NavigationView.java:223)
at android.view.View.measure(View.java:18794)
at android.support.v4.widget.DrawerLayout.onMeasure(DrawerLayout.java:1104)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at com.android.internal.widget.ActionBarOverlayLayout.onMeasure(ActionBarOverlayLayout.java:446)
at android.view.View.measure(View.java:18794)
at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:5951)
at android.widget.FrameLayout.onMeasure(FrameLayout.java:194)
at com.android.internal.policy.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2643)
at android.view.View.measure(View.java:18794)
at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:2100)
at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1216)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1452)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1107)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6013)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:858)
at android.view.Choreographer.doCallbacks(Choreographer.java:670)
at android.view.Choreographer.doFrame(Choreographer.java:606)
最佳答案
大多数设计支持库,包括 NavigationView
,都需要使用 AppCompat。如果您想使用设计库组件,则需要切换回使用 AppCompatActivity
和 AppCompat 主题。
关于android - DrawerLayout、NavigationView 和 android :Theme. Material.Light 不兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37757906/
我需要为我正在处理的应用程序使用 Surface 项目模板,但我也想使用 MVVM Light Toolkit。我发现我可以“添加 | 新项目...”并为 View 、 View 模型或定位器选择一个
我正在使用MVVM Light,并且正在使用消息在ViewModel之间进行通信,以使ViewModel知道何时可以执行某些操作。我的问题是我注册了一条消息,然后多次收到它。因此,要使我的程序不止执行
我目前正在自学MVVM模式。 我第一次碰到了消息传递的概念。 我知道消息传递包含在mvvm-light工具包中。但是我找不到任何地方的用法示例(下载中未提供示例项目)。 如果有人可以指导我了解有关如何
使用Nuget安装MVVM Light Toolkit时,似乎没有安装MVVM Light的片段。 我在哪里可以找到它们? 最佳答案 片段可在 GitHub 上找到. 下载代码(右上角克隆或下载按钮)
我遇到了一个问题,即在 VS 或 Blend 中运行解决方案时,属性 IsInDesignMode 没有返回 true 的预期值。我的环境包括 Win Server 2008 R2、VS2010 Pr
如果我将消息从 ViewModelA 发送到 ViewModelB,是否有办法从我的单元测试中捕获此通知,该单元测试正在测试引发消息的 ViewModelA? Messenger.Default.Se
我尝试使用提供的示例 petstore openapi.json 生成项目。我用过light-codegen生成端点和模型。 我确实安装了 light-codegen: git clone https
这段代码告诉计算机做什么?附注“灯”是一个 boolean 数组。 for (int k = 1; k < lights.length; k++) lights[k]
我有一个包含几个对象和一些对象的场景,在这些情况下,我希望球体受到粉红色和蓝色灯光的影响。但我也有一个管几何结构,它应该只受白光影响,而不受粉红色和蓝色光的影响。 有关问题的演示,请参见下图:现在发生
我正在考虑开始使用 MVVM Light,并且遇到了"new"ICleanup 界面。我只是想知道你什么时候清理虚拟机......当你离开页面时? 另外,我看到 ViewModelLocator 中有
我有一个带有关联虚拟机的子窗口,每次我要求打开子窗口时都会创建该虚拟机。当子窗口打开时,它会为 MVVM Light 消息注册一个监听器。关闭窗口后,我很确定我正在释放对它的所有引用,但我实际上并没有
是否有 MVVM Light DispatcherHelper 可用于 PCL 的时间表?官博中只有备注,暂时不可用。 最佳答案 我刚刚添加了一个 nuget 包,它可以帮助您从 MvvmLight
我正在尝试按照此博客文章中的示例使用 MVVM Light 框架来实现 Metro 风格的分组项目页面,但使用 ViewModelLocator 来提供可混合性: http://mikaelkoski
我们有一个使用 MVVM Light 的 WP8 应用程序,它运行良好。但是,现在我们要使用 Xamarin 来定位 iOS。看来 MvvmCross 是更好的跨平台开发框架。 有没有人有改变这样的框
刚刚注意到 4.2.30 版本不包括 protected bool Set( ref T field, T newValue,
我已经开始使用最新的 MVVM Light 工具包 v4(NuGet 预览版 v4.1.21,DLL v:4.0.21.25725),它实现了 SimpleIOC 模式。 在我的 ViewModelL
我可以使用 Interaction.Triggers 捕获文本框上的 textchanged 事件,如下所示:
我希望这不是一个太愚蠢的问题:我刚刚开始使用 MVVM light(到目前为止很喜欢它!)。在“之前”(即使用 MVVML 之前),我必须通过 ui 分派(dispatch)任何会命中引发 INoti
我在 list 中使用了以下行: android:theme="@android:style/Theme.Light.NoTitleBar" 没有标题栏并在我的应用程序中显示精简版的 AlertDia
“ChainLight”类在其构造函数中有一个名为“rayDirection”的参数: ChainLight(rayHandler, rays, Color, distance, rayDirecti
我是一名优秀的程序员,十分优秀!