Course Content

Course Content

Android Actionbar Example

How to use Actionbar in Android

Here is this video tutorial we will learn about Actionbar and How to use Actionbar in Androidbar in detail.

First, we will create an Actionbar in Android, in this we will use menu.

we will see its manifest file 'AndroidManifest.xml' which is default created.

After that we want to design our project's layout so we will open 'activity_main.xml' file, in which we have simply used relative layout and set some basic properties, and after that we have taken one TextView whose basic properties we have selected.

Now we will design menu for action bar, so for that we will open 'menu_main.xml', now we will set items for menu,

<item

android:title=""@string/add""

android:icon=""@android:drawabld/ic_menu_add""

android:id=""@+id/add""

app:showAction=""always""

android:title=""@string/add""   />

 

Similarly we have designed 'reset', 'about', and 'exit'.

 

Now we will see that how how main file works, so for that inside our 'java' folder, we have created another folder 'actionbar', in which we have 'MainActivity.java' file, we'll open it, and see the default generated code.

Now we have to design a code to display actionbar,

@Override

public boolean onOptionsItemSelected(MenuItem item)

{

switch(item.getItemId())

{

case R.id.add;

count=(TextView)findViewById(R.id.textView);

count.setText(""Add is clicked"");

return(true);

case R.id.reset;

count=(TextView)findViewById(R.id.textView);

count.setText(""Nothing is selected"");

return(true);

case R.id.about;

Toast.makeText(this, R.string.about_toast, Toast.LEMON_LONG.show();

return(true);

case R.id.exit;

finish();

return (true);

}

return (super.onOptionsItemSelected(item));

}

Now we will execute our code, the actionbar which we designed is accurately created and our whole project is running successfully.

FAQs

Recommended Courses

Share With Friend

Have a friend to whom you would want to share this course?

Download LearnVern App

App Preview Image
App QR Code Image
Code Scan or Download the app
Google Play Store
297K+ Downloads
App Download Section Circle 1
4.5 Rating
App Download Section Circle 2
10K+ Reviews
App Download Section Circle 3
  • Learn anywhere on the go
  • Get regular updates about your enrolled or new courses
  • Share content with your friends
  • Evaluate your progress through practice tests
  • No internet connection needed
  • Enroll for the webinar and join at the time of the webinar from anywhere