Monday, August 10, 2015

How To Create Menu and Action Menu


.

How To Create Menu and Action Menu
Using Android Studio 1.4

1) Create New Blank Activitiy

Follow the wizard to create New Blank Activity.

2) Edit res/menu/menu_main.xml

2.1) showAsAction=Never

<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=".MainActivity">
   <item
       android:id="@+id/action_settings"
       android:title="@string/action_settings"
       android:orderInCategory="100"
       app:showAsAction="never/>
</menu>
OUTCOME.

2.2) orderInCategory

<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=".MainActivity">
   <item
       android:id="@+id/action_settings"
       android:title="@string/action_settings"
       android:orderInCategory="100"
       app:showAsAction="never/>
   <item
       android:id="@+id/menu_bookmark"
       android:title="Bookmark"
       android:orderInCategory="99"
</menu>
OUTCOME.

2.3) showAsAction=always

<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=".MainActivity">
   <item
       android:id="@+id/action_settings"
       android:title="@string/action_settings"
       android:orderInCategory="100"
       app:showAsAction="never" />
   <item
       android:id="@+id/menu_search"
       android:title="Search"
       android:orderInCategory="99"
       app:showAsAction="always/>
</menu>
OUTCOME.

2.4) icon

<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=".MainActivity">
   <item
       android:id="@+id/action_settings"
       android:title="@string/action_settings"
       android:orderInCategory="100"
       app:showAsAction="never" />
   <item
       android:id="@+id/menu_search"
       android:title="Search"
       android:icon="@android:drawable/ic_menu_search"
       android:orderInCategory="99"
       app:showAsAction="always" />
</menu>
OUTCOME.

2.5) showAsAction=ifRoom|withText

<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=".MainActivity">
   <item
       android:id="@+id/action_settings"
       android:title="@string/action_settings"
       android:orderInCategory="100"
       app:showAsAction="never" />
   <item
       android:id="@+id/menu_search"
       android:title="Search"
       android:icon="@android:drawable/ic_menu_search"
       android:orderInCategory="99"
       app:showAsAction="ifRoom|withText" />
</menu>

DOWNLOAD

REFERENCES



.

No comments:

Post a Comment