Monday 22 June 2015

ActionBar image attachment example with source code


                                               ActionBar Example in android





main.xml


<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="com.example.androidactionbarexample.MainActivity" >

   
    <item
        android:id="@+id/action_refresh"
        android:icon="@drawable/sync_icons"
        android:orderInCategory="100"
        android:showAsAction="always"
        android:title="Refresh"/>

</menu>


MainActivity.java


package com.example.androidactionbarexample;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Toast;

public class MainActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
// action with ID action_refresh was selected
case R.id.action_refresh:
Toast.makeText(this,
"your select Sync Icon to Refresh selected all service.",
Toast.LENGTH_SHORT).show();
break;

default:
break;
}

return true;
}

}


Example Screen Shot:






Example Code :

                                              Full Source code for ActionBar


Another Example  Screen:








Example Source Code:

                                  Actionbarsherlock lib code

                                  Example Source code for Different Types of Actionbar




No comments:

Post a Comment