How to change text size in places autocompletefragment in android?

前端 未结 6 1749
失恋的感觉
失恋的感觉 2020-12-10 12:11

I am using the PlaceAutocompleteFragment that is provided by google in a project that I am working on right now. But the problem is I need to display the place name that I\'

相关标签:
6条回答
  • 2020-12-10 12:38

    The autoCompleSupportFragment has an EditText Property. Which can be modified accordingly. The name of the editText is however not very clear. In my case, it was "a"

    autoCompleteFragment.a.gravity = Gravity.START

    so to modify the text size, i did:

    autoCompleteFragment.a.textSize = 14.0f
    
    0 讨论(0)
  • 2020-12-10 12:38

    Your screen shot shows that you set margin or padding at search icon and cancel icon. remove it so it make more space for text view.

    You can also use autofittextview library(https://github.com/grantland/android-autofittextview) which will make text size according to your text view size.

    0 讨论(0)
  • 2020-12-10 12:56

    Simplest

     ((EditText)findViewById(R.id.place_autocomplete_search_input)).setTextSize(10.0f);
    

    in case of skadosh answer you need to first get instance of fragment.

    0 讨论(0)
  • 2020-12-10 12:57

    Assuming your fragment in the Javacode is autocompleteFragment, you can use

    autocompleteFragment.a.setTextSize(12.0f);
    
    0 讨论(0)
  • 2020-12-10 13:01

    Using fragment instance you can change the font size and whatever you want with the Search box EditText.. this is how you need to do

    // placeAutocompleteFragment - is my PlaceAutocompleteFragment instance
    ((EditText)placeAutocompleteFragment.getView().findViewById(R.id.place_autocomplete_search_input)).setTextSize(10.0f);
    

    UPDATED: 05/26/20

    Looks like in latest SDK view id is changed to R.id.places_autocomplete_search_input

    0 讨论(0)
  • 2020-12-10 13:01
    View fView = autocompleteFragment.getView();
    

    Set Text, Hint Color & Size:

    EditText etTextInput = fView.findViewById(R.id.places_autocomplete_search_input);
    etTextInput.setTextColor(Color.WHITE);
    etTextInput.setHintTextColor(Color.WHITE);
    etTextInput.setTextSize(12.5f);
    

    Set Search Custom Image:

    ImageView ivSearch = fView.findViewById(R.id.places_autocomplete_search_button);
    ivSearch.setImageResource(R.drawable.ic_search_white);
    

    Set Search Text Clear Image:

    ImageView ivClear = fView.findViewById(R.id.places_autocomplete_clear_button);
    ivClear.setImageResource(R.drawable.ic_close_white);
    

    Output:

    0 讨论(0)
提交回复
热议问题