Android Action Button Icons are missing -
i'm new android & attempting follow tutorials. initial tutorial going hit one
https://developer.android.com/training/basics/actionbar/adding-buttons.html
where i'm finding can't action buttons display icon. if set
android:showasaction="always"
in attempt workaround issue started similar tutorial
http://www.androidhive.info/2013/11/android-working-with-action-bar/
but ended hitting same issue.
i'm using api 11 & not going near support bundle. can text menu items appear in drop down. can't seem icons.
i tried both sets of icons action bar icon set. res folder has following drawable structure
- drawable - drawable-hdpi - drawable-mdpi - drawable-xhdpi - drawable-xxhdpi
with nothing in drawable & appropriate icons in other folders.
this seems such basic step i'm surprised i'm stuck.
any suggestions?
edit: adding code suggested
mainactivity.java
package com.example.gannons.actionbar; import android.support.v7.app.actionbaractivity; import android.os.bundle; import android.view.menu; import android.view.menuitem; public class mainactivity extends actionbaractivity { @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. getmenuinflater().inflate(r.menu.activity_main_actions, menu); return super.oncreateoptionsmenu(menu); } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); //noinspection simplifiableifstatement if (id == r.id.action_settings) { return true; } return super.onoptionsitemselected(item); } }
activity_main_actions.xml
<?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <!-- search / display --> <item android:id="@+id/action_search" android:icon="@drawable/ic_action_search" android:title="@string/action_search" android:showasaction="always" /> <!-- location found --> <item android:id="@+id/action_location_found" android:icon="@drawable/ic_action_location_found" android:title="@string/action_location_found" android:showasaction="always" />
also i'm using android studio in case makes difference.
because activity extends actionbaractivity
, are in fact, using support library (as recommended if want looks consistent api11+ - remember default looks different on api21+). can switch activity extend activity
, you'll use framework version of action bar work activity_main_actions.xml
have written.
otherwise, change android:showasaction
app:showasaction
, , act consistently across api versions.