Frosty
Frosty

Reputation: 93

Put EditText to action bar instead of title

Is it possible to add EditText to action bar layout? Can't find any info about that.

Upvotes: 1

Views: 2176

Answers (2)

Fouad Wahabi
Fouad Wahabi

Reputation: 804

You can create a custom view for your action bar.

Here's how to inflate and add the custom layout to your ActionBar.

 // Inflate your custom layout
final ViewGroup actionBarLayout = (ViewGroup) getLayoutInflater().inflate(
        R.layout.action_bar,
        null);

// Set up your ActionBar
final ActionBar actionBar = getActionBar();
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(false);
actionBar.setDisplayShowCustomEnabled(true);
actionBar.setCustomView(actionBarLayout);
// you can create listener over the EitText
final EditText actionBarText = (EditText) findViewById(R.id.action_bar_text);
actionBarText.addTextChangedListener(this);

Here's a custom layout :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:enabled="false"
android:orientation="horizontal"
android:paddingEnd="8dip" >

<EditText android:id="@+id/action_bar_text"
   <!-- don't forget to define the EditText style here  -->
/> 
</LinearLayout>

So, hope it helps.

Upvotes: 2

Darshil Shah
Darshil Shah

Reputation: 361

Ya it is possible... You can set a custom View for the ActionBar

    ActionBar actionBar = getActionBar();
    actionBar.setCustomView(R.layout.custom_actionbar_view);

For more info check this link

http://www.sanfoundry.com/java-android-program-add-custom-view-actionbar/

Upvotes: 1

Related Questions