我正在使用Android Lollipop(5.0)中使用的新Material Design创建一个应用程序。
我使用以下指南:
http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-pre.html
http://antonioleiva.com/material-design-everywhere/
创建工具栏后,我收到此错误:“以下类无法实例化: - android.support.v7.widget.Toolbar”
该应用程序在手机或模拟器中运行良好,但Android Studio的布局设计器无法正确显示布局。
这里有一些图片:
my_awesome_toolbar.xml布局预览中出错 my_awesome_toolbar.xml中的错误
activity_my.xml布局预览出错 activity_my.xml中的错误
文件的xml代码:
my_awesome_toolbar.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_awesome_toolbar"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
activity_my.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/root"
tools:context="com.myapp.test.MyActivity"
android:orientation="horizontal">
<include
android:id="@+id/toolbar"
layout="@layout/my_awesome_toolbar"
/>
<!-- Rest of layout -->
</RelativeLayout>
MyActivity.java:
package com.myapp.test;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
public class MyActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_my);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
目前我使用Android Studio Beta 0.8.9
蝴蝶不菲
绝地无双