Actions Buttons in Android not visible -


i'm working on first android app following official tutorial. right im trying add action buttons

mainactivity:

@override public boolean oncreateoptionsmenu(menu menu) {     // inflate menu items use in action bar     menuinflater inflater = getmenuinflater();     inflater.inflate(r.menu.main_activity_actions, menu);     return super.oncreateoptionsmenu(menu); } 

res/menu/main_activity_actions.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android" >     <!-- search, should appear action button -->     <item android:id="@+id/action_search"           android:icon="@drawable/ic_action_search"           android:title="@string/action_search"           android:showasaction="ifroom" />     <!-- settings, should in overflow -->     <item android:id="@+id/action_settings"           android:title="@string/action_settings"           android:showasaction="never" /> </menu> 

the application running without errors, search button not displayed. ic_action_search icon placed res/drawable-* , action_search/action_settings defined in strings.xml.

am missing something?

edit: androidmanifest.xml

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"     package="com.example.myfirstapp"     android:versioncode="1"     android:versionname="1.0" >      <uses-sdk         android:minsdkversion="8"         android:targetsdkversion="19" />      <application         android:allowbackup="true"         android:icon="@drawable/ic_launcher"         android:label="@string/app_name"         android:theme="@style/apptheme" >         <activity             android:name="com.example.myfirstapp.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="com.example.myfirstapp.displaymessageactivity"             android:label="@string/title_activity_display_message"             android:parentactivityname="com.example.myfirstapp.mainactivity" >             <meta-data                 android:name="android.support.parent_activity"                 android:value="com.example.myfirstapp.mainactivity" />         </activity>     </application>  </manifest> 

styles.xml

<resources>      <!--         base application theme, dependent on api level. theme replaced         appbasetheme res/values-vxx/styles.xml on newer devices.     -->     <style name="appbasetheme" parent="theme.appcompat.light">         <!--             theme customizations available in newer api levels can go in             res/values-vxx/styles.xml, while customizations related             backward-compatibility can go here.         -->     </style>      <!-- application theme. -->     <style name="apptheme" parent="appbasetheme">         <!-- customizations not specific particular api-level can go here. -->     </style>  </resources> 

as per document

if app using support library compatibility on versions low android 2.1, showasaction attribute not available android: namespace. instead attribute provided support library , must define own xml namespace , use namespace attribute prefix. (a custom xml namespace should based on app name, can name want , accessible within scope of file in declare it.) example:

<menu xmlns:android="http://schemas.android.com/apk/res/android"       xmlns:yourapp="http://schemas.android.com/apk/res-auto" >     <item android:id="@+id/action_search"           android:icon="@drawable/ic_action_search"           android:title="@string/action_search"           yourapp:showasaction="ifroom"  />     ... </menu> 

you missing custom namespace in main_activity_actions.xml. remove yourapp name of app or anything.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -