java - No resource identifier found for attribute 'showAsAction' in package "..." -
i trying modify default empty activity , form default activity action bar. there 2 activities made, both empty without actionbar. try achieve click on first activity(without actionbar) , navigate second activity(with actionbar). have done are:
1. add menu
2. modify second activity changing activity appcompatactivity
3. add support library v7-appcompat (which added referenced library. not sure whether should referenced lib or other format.)
manifest file part shown below:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.tracker" android:versioncode="1" android:versionname="1.0" > <uses-sdk android:minsdkversion="14" android:targetsdkversion="21" /> <application android:allowbackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@style/apptheme" > <activity android:name=".mainactivity" android:label="@string/app_name" > <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> <activity android:name=".secondactivity" android:label="@string/second" > </activity> </application> </manifest>
the first activity is:
package com.example.tracker; import android.app.activity; import android.content.intent; import android.os.bundle; import android.view.view; import android.widget.button; public class mainactivity extends activity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); //get button button button1 = (button)findviewbyid(r.id.button1); button1.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub intent intent= new intent(mainactivity.this,secondactivity.class); intent.setaction(intent.action_view); startactivity(intent); } }); } }
the second activity is:
package com.example.tracker; import android.app.activity; import android.content.intent; import android.os.bundle; import android.support.v7.app.actionbar; import android.support.v7.app.appcompatactivity; import android.view.menu; import android.view.menuitem; import android.widget.toast; public class secondactivity extends appcompatactivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_second); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.main, menu); return true; } @override public boolean onoptionsitemselected(menuitem item) { return super.onoptionsitemselected(item); } }
the menu in res is:
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" tools:context="com.example.tracker.mainactivity" > <item android:id="@+id/myitem" android:orderincategory="2" android:title="myitem" app:showasaction="never"/> <item android:id="@+id/action_settings" android:orderincategory="1" android:title="action_settings" app:showasaction="never"/> </menu>
the observable problem menu has error written in title of problem. currently, first activity can run properly, however, when click button, application stops.
by removing app:showasaction="never" not solve problem.
Comments
Post a Comment