Android Question [SOLVED] How to change width of AppCompat ACSearchView

Discussion in 'Android Questions' started by Brandsum, Nov 22, 2018.

Tags:
  1. Brandsum

    Brandsum Active Member Licensed User

    Hi, @corwin42
    I have an issue. ACSearchView width is not 100%. Here is my code:

    Code:
    Sub Activity_CreateMenu(Menu As ACMenu)
        SearchBar.Initialize2(
    "Search", SearchBar.THEME_DARK)
        SearchBar.QueryHint = 
    "Search for stores"
        SearchBar.IconifiedByDefault = 
    True
     
        
    Menu.Clear
        MenuItemHelper = 
    Menu.Add(0,0,"Search",FontToBitmap(Chr(0xE8B6),True,35,Colors.White))
        MenuItemHelper.ShowAsAction = MenuItemHelper.SHOW_AS_ACTION_ALWAYS
        MenuItemHelper.SearchView = SearchBar
    End Sub
    For the output check screenshot attached.

    6028914888491454213.png

    How can I change the width?
     
    Last edited: Nov 22, 2018
  2. Brandsum

    Brandsum Active Member Licensed User

    Issue Solved.

    android.support.v7.widget.searchview has a method for changing the width.
    https://developer.android.com/reference/android/widget/SearchView.html#setMaxWidth(int)

    So calling that method using Reflector solved my issue.

    Code:
    Sub Activity_CreateMenu(Menu As ACMenu)
        SearchBar.Initialize2(
    "Search", SearchBar.THEME_DARK)
        SearchBar.QueryHint = 
    "Search for stores"
        SearchBar.IconifiedByDefault = 
    True
        
    '
        Dim r As Reflector
        r.Target = SearchBar
        r.Target = r.GetField(
    "mSearchView")
        r.RunMethod4(
    "setMaxWidth"Array As Object(Activity.Width), Array As String("java.lang.int"))
        
        
    Menu.Clear
        
    Menu.Add(0,0,"Search",FontToBitmap(Chr(0xE8B6),True,35,Colors.White)).ShowAsAction = MenuItemHelper.SHOW_AS_ACTION_ALWAYS
        
    Menu.GetItem(0).SearchView = SearchBar
    End Sub
    6144008216986780300.jpg
     
    inakigarm and DonManfred like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice