Estou criando um aplicativo com o novo Material Design usado no Android Lollipop (5.0).
Estou usando os seguintes guias:
- http://android-developers.blogspot.it/2014/10/appcompat-v21-material-design-for-pre.html
- http://antonioleiva.com/material-design-everywhere/
Depois de criar minha barra de ferramentas, recebo este erro: "As seguintes classes não puderam ser instanciadas: - android.support.v7.widget.Toolbar"
O aplicativo funciona bem no telefone ou emulador, mas o designer de layout do Android Studio não mostra o layout corretamente.
Aqui estão algumas imagens:
Erro na visualização do layout my_awesome_toolbar.xml
Erro na visualização do layout activity_my.xml
O código xml dos arquivos:
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);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.my, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
código xml dos estilos (values / styles.xml):
<resources>
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<item name="colorPrimary">@color/blue</item>
<item name="colorPrimaryDark">@color/dark_blue</item>
<item name="actionOverflowButtonStyle">@style/AppTheme.OverflowButtonStyle</item>
</style>
<!-- Style Title -->
<style name="Title">
<item name="android:textColor">@color/white</item>
<item name="android:textStyle">bold</item>
<item name="android:textSize">16sp</item>
</style>
<style name="AppTheme.OverflowButtonStyle" parent="Widget.AppCompat.ActionButton.Overflow">
<item name="android:src">@drawable/overflow_icon</item>
</style>
</resources>
No momento, uso o Android Studio Beta 0.8.9
Toolbar
renderização.