关于如何在Eclispe中使用V7包下的Toolbar

现在想按照大神们的博客改造自己的ActionBar,自己写了一个测试项目,但运行总是奔溃,代码如下
package com.example.testapplication;

import android.app.Activity;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.Window;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
     Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);

// toolbar.setNavigationIcon(R.mipmap.ic_launcher);//设置导航栏图标
toolbar.setLogo(R.drawable.ic_launcher);//设置app logo
toolbar.setTitle("Title");//设置主标题
toolbar.setSubtitle("Subtitle");//设置子标题

   toolbar.inflateMenu(R.menu.activity_tool_bar);//设置右上角的填充菜单
   //点击事件
   toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() {
       @Override
       public boolean onMenuItemClick(MenuItem item) {

           switch (item.getItemId()){
               case R.id.action_item1:
                   //........
               case R.id.action_item2:
                   //........

           }

           return true;
       }
   });

}

}

布局如下
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.testapplication.MainActivity" >

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ff0" >
</android.support.v7.widget.Toolbar>

报错提示:
Caused by: java.lang.ClassNotFoundException: Didn't find class "com.example.testapplication.MainActivity" on path: DexPathList[[zip file "/data/app/com.example.testapplication-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.example.testapplication-2, /system/lib]]

搞了两天了,Toolbar连样子都没见到,谢谢各位大N先!!!

查看全部
xiangwei132
xiangwei132
2016/12/12 11:50
  • launcher
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复