如何删除SearchView内部文本/布局的内部底部空间(底部边距/填充)?

时间:2015-11-23 13:51:16

标签: android android-layout android-view searchview android-search

所以我得到了这个SearchView,它底部的文本底部有一个默认空间。如何减少它(见图中的红线):

enter image description here

1 个答案:

答案 0 :(得分:4)

  1. 想象一下,SearchView名为searchBar

    SearchView searchBar = (SearchView) findViewById(R.id.searchViewBar);
    
  2. 获取包含AutoCompleteTextView内文字的视图(SearchView):

     //The view that contains the SearchView text
     AutoCompleteTextView searchTextContent = (AutoCompleteTextView) searchBar.findViewById(searchBar.getContext().getResources().getIdentifier("android:id/search_src_text", null, null));
    
     searchTextContent.setTextSize(15); //Set the text size
     searchTextContent.setGravity(Gravity.BOTTOM); //Set its gravity to bottom
    
  3. 您可以使用AutoCompleteTextView方法(如setHeight(),setPadding()等)来操作此视图。更多信息here