无法应用AppCompatActivity中的setSupportActionBar(androidx.appcompat.widget.Toolbar) [英] setSupportActionBar (androidx.appcompat.widget.Toolbar) in AppCompatActivity cannot be applied

查看:507
本文介绍了无法应用AppCompatActivity中的setSupportActionBar(androidx.appcompat.widget.Toolbar)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

显示不兼容类型的错误,而在Android Studio上工作时,无法在Java编译器中转换Android小部件工具栏.

An error showing incompatible types Android widget toolbar cannot be converted in Java compiler while working on Android Studio.

    Toolbar toolbar = (Toolbar)findViewById(R.id.toolBar);
    toolbar.setTitle("GPS PRESENCE SYSTEM");
    setSupportActionBar(toolbar);

错误:类型不兼容:android.widget.Toolbar无法转换 到androidx.appcompat.widget.Toolbar

Error: incompatible types: android.widget.Toolbar cannot be converted to androidx.appcompat.widget.Toolbar

推荐答案

尝试替换为:

import android.widget.Toolbar;

与此:

import androidx.appcompat.widget.Toolbar;

顺便说一句,如果您使用的是androidx.运行它的迁移过程. 以后将不再支持android支持库. 您可以在这里阅读有关内容:

By the way, if you are using androidx. Run it's migration process. The android support libraries will not be supported in the future. You can read about it here:

AndroidX 迁移到AndroidX

这篇关于无法应用AppCompatActivity中的setSupportActionBar(androidx.appcompat.widget.Toolbar)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆