Reputation: 1949
I've some issues with width of this element when I put it on a toolbar or actionbar. Look like this:
No problems with SearchView:
With SearchView it will be ok, but don't wanna be putting workaround in my code. What can I do? I'm using the last version of appcompat library.
search_custom:
<AutoCompleteTextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/autoCompleteTextView_searchWidget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp"
android:textColor="@color/black"
android:imeOptions="actionSearch"
android:inputType="text">
<requestFocus/>
</AutoCompleteTextView>
Menu.xml:
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item android:id="@+id/action_search"
android:name="search"
android:title="@string/search"
android:imeOptions="actionSearch"
android:inputType="textAutoComplete|textAutoCorrect"
app:actionLayout="@layout/search_custom"
android:icon="@drawable/ic_search"
app:showAsAction="ifRoom|collapseActionView"/>
</menu>
Gradle:
compile 'com.android.support:appcompat-v7:21.0.+'
SOLVED! BEAUTIFUL WORKAROUND:
int screenWidth = new ViewUtil(this).getScreenWidth(); // This guy return the width of the device
if(screenWidth <= 10) {
creenWidth = 150;
}
mAutoCompleteTextView.setMinWidth(screenWidth);
Upvotes: 0
Views: 1599
Reputation: 327
In my case work this code:
textView.setLayoutParams(new ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT));
Upvotes: 0
Reputation: 155
Looks like you are missing the minWidth on your AutoCompleteTextView
Upvotes: 3