Hello i wanna make my EditText to occupy all of my toolbar when i clicked it and i want that after the user ends typing to make the toolbar go back to normal.
Here is my xml file for the menu
<item android:id="@+id/action_search"
android:title="search"
android:orderInCategory="100"
android:icon="@drawable/search"
app:showAsAction="ifRoom"
/>
And here is my java code
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()){
case R.id.action_search :
search.setHint("Procura");
toolbar.addView(search);
toolbar.setBackgroundColor(Color.WHITE);
search.setOnEditorActionListener(new EditText.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_SEARCH ||
actionId == EditorInfo.IME_ACTION_DONE ||
event.getAction() == KeyEvent.ACTION_DOWN &&
event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
// the user is done typing.
SearchActivity.this.text = search.getText().toString();
return true;
}
return false;
}
});
return true;
default : return super.onOptionsItemSelected(item);
}
}
Thank you in advance.