我决定制作自己的工具栏
所以我删除了常规工具栏:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="false"
android:theme="@style/Theme.AppCompat.Light.NoActionBar> //removetollbar
并制作我自己的工具栏
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</android.support.v7.widget.Toolbar>
然后我包含在主 xml 中
<include
layout="@layout/customtoolbar"
android:id="@+id/custombar" >
</include>
在代码中我设置了它:
_CustomToolBar = (android.support.v7.widget.Toolbar)
findViewById(R.id.custombar);
setSupportActionBar(_CustomToolBar);
android.support.v7.widget.Toolbar _CustomToolBar;
now when the app run the custom toolbar is not there
请帮忙。
最佳答案
在您的 <include>
中标签,您已将工具栏的 id 设置为 @+id/custombar
,但您正在使用 R.id.toolbar
进行查找。将该行更改为:
_CustomToolBar = (android.support.v7.widget.Toolbar) findViewById(R.id.custombar);
关于java - 自定义工具栏不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49018118/