gpt4 book ai didi

Android Studio - 呈现支持库问题

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:43:33 24 4
gpt4 key购买 nike

我在使用来自谷歌支持库(appcompat-v7、support-v4)的类时,在 Android Studio 中呈现布局预览时遇到问题。

示例(同样适用于支持库中的所有其他元素):

The following classes could not be found: - android.support.v7.widget.Toolbar (Fix Build Path, Edit XML, Create Class)

库被添加到build.gradle的依赖列表中:

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'com.android.support:support-v4:22.1.1'
}

问题是,当我将 XML 中的类名更改为 <Toolbar> 时而不是 <android.support.v7.widget.Toolbar> ,一切都完美呈现,但它不会在旧的 API 版本上运行。更改呈现 API 版本并不能解决问题,更改应用主题或构建/清理项目也不能解决问题。

该应用程序可以在旧版和新版 API 上运行,没有任何问题 - 只是渲染让我很烦,因为我已经尝试了我在 Stack Overflow 上找到的关于此类问题的所有内容,但我仍然无法修复它。在我看来,Android Studio 布局渲染器看不到添加到依赖项列表中的类。

下面是我的自定义应用程序工具栏的代码:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:paddingTop="@dimen/padding_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/primaryColor"
app:theme="@style/CustomToolbarTheme"
/>

最佳答案

看看 Nadir Williams 的回答 here .他说

Isnt the theme attribute supposed to be android:theme now instead of app:theme?

有帮助吗?

关于Android Studio - 呈现支持库问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29856756/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com