2

I set a smaller text size than the default in my AutoCompleteTextView, expecting the dropdown list of suggestions to have identical text size and font. However, clearly it is different. The suggestions list text size stayed the same while the EditBox (AutoCompleteTextView) text size was changed when I set it in the activity_main.xml with android:textSize="15dp". Here is the result.

enter image description here

I searched for a property that might control suggestions' text size but could not find it. What is the way to ensure that all text is the same size, suggestion and editbox.

Here is the code in case it is needed.

public class MainActivity extends AppCompatActivity {
    private static String [] countries = new String[] {"Vatican", "Brazil",
            "Switzerland", "Angola", "Haiti", "Puerto Rico", "Germany", "Mexico",
            "France", "Ireland", "India", "Australia", "Zimbabwe", "South Africa",
            "Canada", "Thailand", "Japan", "Chile", "Botswana", "El Salvador", "Cuba",
            "Vietnam", "Mongolia", "Morocco", "Italy", "Portugal", "Ukrain"
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Set up autocomplete widget
        AutoCompleteTextView countryTV = (AutoCompleteTextView) findViewById(R.id.autoCompleteQuery);

        ArrayAdapter<String> countriesList = new ArrayAdapter<>(this,
                android.R.layout.simple_list_item_1, countries);
        countryTV.setAdapter(countriesList);
}

XML

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#eeeeee"
    tools:context=".MainActivity">


    <AutoCompleteTextView
        android:id="@+id/autoCompleteQuery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="375dp"
        android:layout_marginEnd="8dp"
        android:layout_marginLeft="16dp"
        android:layout_marginRight="8dp"
        android:layout_marginStart="16dp"
        android:layout_marginTop="8dp"
        android:background="@android:color/white"
        android:hint="Select Country"
        android:padding="10dp"
        android:textSize="15dp"
        android:singleLine="true"
        android:textColor="@android:color/black"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

Thanks

driftwood
  • 2,051
  • 4
  • 21
  • 28

2 Answers2

0

android.R.layout.simple_list_item_1 uses textAppearance and not textSize. it uses below value.

android:textAppearance="?android:attr/textAppearanceListItemSmall"

You either need to set this textAppearance value to your AutocompleteTextView or create separate layout with TextView values you want and use it as custom resource in place of android.R.layout.simple_list_item_1 while setting adapter.

karan
  • 8,637
  • 3
  • 41
  • 78
-1

Use custom layout for item of ArrayAdapter like below:

item_layout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@android:color/white">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="10dp"
        android:textSize="15dp"
        android:singleLine="true"
        android:textColor="@android:color/black"
        android:background="@android:color/white"/>
</LinearLayout>

Set layout in Array Adapter

ArrayAdapter<String> countriesList = new ArrayAdapter<>(this,
               R.layout.item_layout, countries);
countryTV.setAdapter(countriesList);

I hope its work for you.

Android Geek
  • 8,956
  • 2
  • 21
  • 35
  • RootView must be TextView - see https://stackoverflow.com/questions/9280965/arrayadapter-requires-the-resource-id-to-be-a-textview-xml-problems – Josef Vancura Jan 29 '21 at 15:35