android - support.v7.widget.Toolbar 报错
PHP中文网
PHP中文网 2017-04-17 13:36:46
0
1
603
   <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_height="wrap_content"
        android:layout_width="match_parent"
        android:minHeight="?attr/actionBarSize"
        android:background="@drawable/actionbar_bg_gradient_light"
        app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

出现以下的错误

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') 
PHP中文网
PHP中文网

认证0级讲师

reply all(1)
Peter_Zhu

A few steps to use support-v7:

  • Import appcompat_v7 project (android-sdkextrasandroidsupportv7appcompat)
  • Modify appcompat_v7 build-target to 21 and above
  • Declare appcompat_v7 as a library project (select the project name - shortcut key Alt+Enter - Android - check Is Library)
  • Add the jars in appcompat_v7libs to Build path
  • Modify your project build-target to 21 and above
  • Reference appcompat_v7 in your own project, select your project name - shortcut key Alt+Enter - Android - add - appcompat_v7 - ok
  • Modify your project theme to the style in appcompat_v7/res/values/themes.xml

Pay attention to check whether the style of the Eclipse layout preview is the style defined by 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>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template