Reputation: 1027
I have created menu
folder in res
. Inside the menu
folder I created a menu_main.xml file which contains:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="@+id/action_settings" android:title="action_settings"
android:orderInCategory="100" android:showAsAction="never" />
</menu>
Since I'm using this xml in conjunction with a code inside MainActivity
. It gives me an error of "Cannot resolve symbol for menu_main
. Below is the snippet:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
I cannot understand why this is happening even after creating the xml in a specified folder. Maybe I'm missing something silly but I can't get a hold of it. Any help would be appreciated.
Upvotes: 0
Views: 1697
Reputation: 6035
android:showAsAction="always"
here you go.! try to follow Proper Android Developer Documentation Menus
and this Tutorial Will help you too.! Menu Example And Last go to file click on Invalidate Caches and Restart.! hope this will help u.!
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
<item android:id="@+id/action_settings" android:title="action_settings"
android:orderInCategory="100" android:showAsAction="always" />
</menu>
Upvotes: 1
Reputation: 52
why are you using android:showAsAction="never"
<?xml version="1.0" encoding="utf-8"?><menu xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity"><itemandroid:id="@+id/action_settings" android:title="action_settings"
android:orderInCategory="100" android:showAsAction="always" ></menu>
try this code
Upvotes: 2
Reputation: 31
Clean and rebuild your project by going to Build>Clean
Project.
Go to File>Invalidate Caches/Restart
.
Upvotes: 2
Reputation: 20910
If you have lot of cache memory store by IDE so IDE can not identify that time you have to Clean
and Rebuild
the Project. And if the IDE contains lots of caches memory that time you have to clean that memory the Restart it.
That time you have to go to File and Select Invalidate Caches and Restart
.
Upvotes: 1