I want to show an AutoCompleteTextView that is always expanded in my ActionBar
. This is my menu xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/visibility_menu_search"
android:icon="@drawable/ic_action_search"
android:showAsAction="always"
android:actionLayout="@layout/visibility_search" />
</menu>
This is my layout/visibility_search.xml
<AutoCompleteTextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/visibility_search_auto_complete_text_view" />
This is my Activity:
public class VisibilityActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(layout.visibility_activity);
getActionBar().setDisplayShowTitleEnabled(false);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.visibility, menu);
return super.onCreateOptionsMenu(menu);
}
}
I'm using showAsAction="always"
because I want the AutoCompleteTextView
to always be visible (it will be the only thing in the ActionBar
).
My AutoCompleteTextView
is always right-aligned in the ActionBar
and only has 100px width. Why is this?
Update
Thanks to Atul O Holic's answer, I found a preferred solution for my case, which doesn't require any special logic at all. I'm leaving my answer as correct because it works for the general case, but for my specific case, a SearchView
is better and easier.