【问题标题】:Cannot resolve class android.support.v7.widget.Toolbar [closed]无法解析类 android.support.v7.widget.Toolbar [关闭]
【发布时间】:2021-09-12 18:23:13
【问题描述】:

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

}

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

【问题讨论】:

  • textArea.setText(textArea.getText() + text + "\r\n");
  • @GilbertLeBlanc,不要使用 setText(...)。这将导致 Document 删除 Document 的所有现有元素,然后需要重新解析文本以重建 Document 的元素。当您可以使用append(.,..) 方法或Document.insertString(...) 方法时,会有很多不必要的工作。此外,文档仅将“\n”存储为换行符字符串。

标签: java android-studio navigation-drawer


【解决方案1】:

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

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

改为使用append(...) 方法。比如:

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

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

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

【讨论】:

    猜你喜欢
    • 2020-08-26
    • 2014-12-21
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 1970-01-01
    • 1970-01-01
    • 2016-12-06
    相关资源
    最近更新 更多