Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community!
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.Start your free trial
Android menu Action Bar
I'm adding the sharing icon to the action bar but have run into a couple of problems.
Firstly, within the 'menu' folder, I don't have a file called
activity_blog_web_view.xml; mine is just
blog_web_view.xml - no big deal.
However, there's nothing inside that at all. There's no file to delete. Again, no big deal.
The showstopper here is the inability to add anything. I click the 'Add' button and there's nothing to select - there's no Group or Item option. I get a modal window with the heading "Create a new element at the top level, in Temp" - but there's no options to select. (Why Temp??)
So I can't select anything to add; the OK button is greyed out.
Any thoughts? Is this because
Activity rather than
ActionBarActivity? (I'll try that!)
Done that - and it still doesn't work. But chasing the errors around makes it look like I've done something wrong implementing this Activity.
Potentially, if we can understand why the .xml isn't called
activity_blog_web_view.xml then we'll understand what I did wrong.
This seems to be a resource issue of my creation!
As always, Ben Jakuben ; massive thanks for your direct help. #Legend
Ben JakubenTreehouse Teacher
Very strange! Sounds like a tools bug. I'll have to look into this. In the mean time, can you edit the XML directly? If so, here's what the XML view of the file should look like:
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_share" android:icon="@drawable/ic_action_share" android:showAsAction="always" android:title="@string/action_share"> </item> </menu>
Exactly like that, yes.
I've done all that.
On the plus-side, I now have icons in the layout file and can add groups or items. That's progress!
However, every reference to
R. now generates an error in both classes. I've organised imports and the errors changed from the
R. itself to the parameter such as
activity_blog_web_view. Those are named correctly but don't appear in the drop-down helper when creating or editing code. The error says:
Multiple markers at this line: webView1 cannot be resolved or is not a field R cannot be resolved to a variable
Console has the following errors which may be related:
[2014-05-30 09:32:16 - BlogReader] W/ResourceType(17370): ResXMLTree_node header size 0xc is too small. [2014-05-30 09:32:16 - BlogReader] /Users/OnlySteveH/Dropbox/Android Apps/BlogReader/res/menu/blog_web_view.xml:6: error: Error: No resource found that matches the given name (at 'title' with value '@string/action_share').
I'll figure out how to zip the files and send them over.