首页 > 解决方案 > 无法解析类 android.support.v7.widget.Toolbar

问题描述

我正在尝试制作一个带有工具栏的 android 应用程序,但我收到了上述错误消息。问题是什么?到目前为止,我用什么 youtube 视频创建了我的程序(我是一个初学者),但现在我被困住了:我的 build.gradle 文件的依赖关系与 youtube 视频中的依赖关系不同。例如,我没有以下实现:implementation 'com.android.support:appcompat-v7:26.1.0' 如果我有这一行,一切都会好起来的,如果我可以将其复制并粘贴到下一行中,则将其更改为implementation 'com.android.support:design:26.1.0' This is the code in my activity_main.xml 文件,错误发生在这里:

xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/drawer_layout"
    android:fitsSystemWindows="true"
    tools:context=".MainActivity">
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="#FFFFFF"
        android:elevation="4dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />`

这是我的 build.gradle 文件的依赖项:

依赖{

implementation 'androidx.appcompat:appcompat:1.4.0'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.2'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'

}

我能做些什么?我希望你能回答我的问题。

标签: javaandroid-studionavigation-drawer

解决方案


问题是第一次显示的文本被“删除”,因为现在显示的是其他文本而不是第一个文本。

不要使用该setText(...)方法。这将在添加新文本之前删除现有文本。

而是使用该append(...)方法。就像是:

textArea.append("\nAnother line of text.");

将文本附加到文档的末尾。

或者您可以使用该Document.insertString(...)方法在文本区域的 Document 中的任意位置插入新文本。


推荐阅读