Introduction
This article explains about CustomView in the Action Bar.
In this article, you can add the EditText to the ActionBar. Inside the EditText, if you type any value and on click then you can show that value as a notification in your Activity.
For this, you will use an EditText in your XML file. First, you will get an object of ActiuoBar by calling the getActionBar() method. After getting the object of Action you will cal the setCustomVIew (int resid) method to the set EditText in the Action Bar. Now you will get the id of the CustomView EditText with this:
Now you need to show the data as a Toast on the Activity so you will set the EditText on setOnEditorActionListener(). When you click anywhere on the screen notification will appear.
- final EditText edittext = (EditText) actionBar.getCustomView().findViewById(R.id.edittext);
- getCustomView(): It returns a CustomView
- search.setOnEditorActionListener(new OnEditorActionListener()
- {
- @Override
- public boolean onEditorAction(TextView v, int actionId, KeyEvent event)
- {
- String a = search.getText().toString();
- //textview.setText(a);
- Toast.makeText(MainActivity.this, a, Toast.LENGTH_LONG).show();
- return false;
- }
- });
Now you will set the CustomView display using the setDisplayOptions() method:
- bar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM
- ActionBar.DISPLAY_SHOW_HOME);
Step 1

Step 2
- <?xml version="1.0" encoding="utf-8"?>
- <EditText xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/edittext"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:inputType="textFilter" >
- </EditText>


Join the conversation! Your thoughts help the community grow.