android - support.v7.widget.Toolbar 报错

 mobiledu2502858053 发布于 2022-11-02 14:11
   

出现以下的错误

No resource found that matches the given name(at'minHeight'with value'?attr/actionBarSize') 
No resource found that matches the given name(at'theme'with value'@style/ThemeOverlay.AppCompat.Dark.ActionBar') 
No resource found that matches the given name(at'popupTheme'with value'@style/ThemeOverlay.AppCompat.Light') 
1 个回答
  • 使用 support-v7 的几个步骤:

    • 导入 appcompat_v7 项目(android-sdk\extras\android\support\v7\appcompat)
    • 修改 appcompat_v7 build-target 为 21及以上
    • 声明 appcompat_v7 为库项目(选中项目名 - 快捷键 Alt+Enter - Android - 勾选 Is Library)
    • 将 appcompat_v7\libs 里面的jar add to Build path
    • 修改自己项目 build-target 为 21及以上
    • 在自己的项目引用 appcompat_v7 , 选中自己项目名 - 快捷键 Alt+Enter - Android - add - appcompat_v7 - ok
    • 修改自己项目theme 为 appcompat_v7/res/values/themes.xml 里的 style

    注意检查 Eclipse 布局预览的 样式是否是 appcompat_v7 定义过的样式.

    <!-- 一段可用的布局代码 -->
    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolBar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentTop="true"
            android:background="#d8d8d8"
            android:minHeight="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />
    
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/toolBar"
            android:orientation="vertical" >
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/hello_world" />
        </LinearLayout>
    
    </RelativeLayout>
    
    2022-11-04 07:54 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有