Wednesday, 6 June 2012

Setting the App Name/Icon in the action bar

creating the actionBar write this code onside the oncreate



 setContentView(R.layout.main);
        ActionBar ac=getActionBar();
       // ac.setDisplayOptions(0,ActionBar.DISPLAY_USE_LOGO);
        ac.setDisplayShowTitleEnabled(true);
       // ac.setDisplayShowHomeEnabled(false);
        ac.setTitle("Restaurant");
        ac.setIcon(R.drawable.ic_new);
 



this is the code for creating option menu



public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.my_menu, menu);
        return true;
    }
   
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {   
        case MENU_NEW_GAME:       
            newGame();       
            return true;   
        case MENU_QUIT:       
            quit();       
            return true;   
    }   
    return false;
   
   
   
    }



this is the code for creating the method

    private void quit() {
        // TODO Auto-generated method stub
       
    }

    private void newGame() {
        // TODO Auto-generated method stub
       
    }



this should be created inside the string.xml

    <string name="hello">Hello World, RestCookActivity!</string>
    <string name="app_name">RestCook</string> 
    <string name="new_game">New Game</string>
    <string name="quit">Quit</string>




create the mymenu.xml


<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
 <item android:id="@+id/new_game"
          android:title="@string/new_game"
          android:icon="@drawable/ic_new"
          android:showAsAction="ifRoom|withText"
         
          />
          
    <item android:id="@+id/quit"
        android:title="@string/quit"
        android:icon="@drawable/ic_quit"     
          android:showAsAction="ifRoom|withText"
         
         
           />
   

</menu>






No comments:

Post a Comment