java - 自定义工具栏不存在

标签 java android android-layout material-design android-toolbar

我决定制作自己的工具栏

所以我删除了常规工具栏:

<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/

相关文章:

java - Android 和 Garmin FR230 (SDK 1.3.x) 之间通过 BLE 的直接消息通信失败

android - 如何在android中的 ImageView 中显示具有固定Uri的图像

android - 识别使用缺少 AttributeSet 的 View 构造函数时的错误

java - 通过 JTable 从 ArrayList 中删除项目

java - spring、hibernate、log4j 用于集中错误捕获

android broadcastreceiver 与听众

java - 如何在选项卡 Activity 中调用微调器?

java - 为什么人们会选择在接口(interface)中使用静态方法而不是默认方法

java - Dropbox 数据存储 API : Reliably determining if the user is authenticated

android - 使用数据绑定(bind)后查看边距不起作用