Java 无法将线性布局强制转换为工具栏
我尝试按照这里的方法将阴影添加到工具栏 它在我的设备上崩溃了,这些是错误 我不知道如何发布代码,因为网站一直告诉我,即使做了很多事情,代码也没有格式化,所以这里有一个粘贴桶链接 这是工具栏布局Java 无法将线性布局强制转换为工具栏,java,android,android-layout,android-studio,android-toolbar,Java,Android,Android Layout,Android Studio,Android Toolbar,我尝试按照这里的方法将阴影添加到工具栏 它在我的设备上崩溃了,这些是错误 我不知道如何发布代码,因为网站一直告诉我,即使做了很多事情,代码也没有格式化,所以这里有一个粘贴桶链接 这是工具栏布局 <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="top" android:orientation="vertical" xm
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.v7.widget.Toolbar
style="@style/ToolBarStyle"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/colorPrimary"
android:minHeight="@dimen/abc_action_bar_default_height_material"
android:id="@+id/toolbar_actionbar"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- **** Place Your Content Here **** -->
<View
android:layout_width="match_parent"
android:layout_height="5dp"
android:background="@drawable/toolbar_dropshadow" />
</FrameLayout>
}
我应该怎么做才能消除这些错误,请帮助您需要更改
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
到
您应该检查
活动\u main.xml
布局
在此布局中,您将使用带有
您必须更改此id。xml和代码在哪里?@PedroOliveira我现在添加了工具栏布局,但忘记添加了。已编辑,这些是错误我仍然看不到代码显示您的MainActivity.java类代码已添加…我希望您谈论的是工具栏布局,能否刷新..抱歉,我发布了修改后的工具栏布局,将其更改为原始,id为toolbar\u actionbar..除此之外,我没有收到其他错误,应用程序只是在设备上崩溃如果这确实是您当前的代码(因为您甚至无法将正确的代码复制粘贴到答案),那么它将无法生成强制转换异常。检查你的
activity\u main
,看看它是否真的与你在这里发布的内容相匹配。确实如此,我刚刚将工具栏布局包括到了主活动中什么?你包括什么?这应该是activity\u main.xml
的内容。不是包含布局的内容。您的活动\u main
应该与您发布的内容相似……您不需要
什么都不做
mToolbar = (Toolbar) findViewById(R.id.toolbar_actionbar);
mToolbar = (Toolbar) findViewById(R.id.tool_bar);
id ="toolbar_actionbar"