Android Question Problem in AC library

omidaghakhani1368

Well-Known Member
Licensed User
Longtime User
Hi again and i'm sorry for ask many question.
I'm working with appcompat library
I have 2 problem please help me to solve this problems
1- How to change ACActiomMode Background color ? ( for me always black)
2- How to work with ACSearchview (im initializing but cant show?)
 

corwin42

Expert
Licensed User
Longtime User
Hi again and i'm sorry for ask many question.
I'm working with appcompat library
I have 2 problem please help me to solve this problems
1- How to change ACActiomMode Background color ? ( for me always black)
2- How to work with ACSearchview (im initializing but cant show?)

It's better to ask each question in its own thread if they are not really related.

1: You have to change the theme xml file. See this or this answer on StackOverflow.

2: This is a bit like an undocumented feature. I never found the time to write a tutorial about it.

- Initialize the SearchView with an EventName
- Set it Iconified state by default sv.IconifiedByDefault = True
- You have to use the advanced menu. I usually set it up with some java code. si is of type ACMenuItem,
UIUtils.GetBitmapDrawable just loads a drawable. Just create a menu item and assign the searchview to it:
:
B4X:
#If Java

    public boolean _onCreateOptionsMenu(android.view.Menu menu) {
    if (processBA.subExists("activity_createmenu")) {
        processBA.raiseEvent2(null, true, "activity_createmenu", false, new de.amberhome.objects.appcompat.ACMenuWrapper(menu));
        return true;
    }
    else
        return false;
}
#End If

Sub Activity_CreateMenu(Menu As ACMenu)
    Menu.Clear
    si = Menu.Add2(1, 1, "Add location", UIUtils.GetBitmapDrawable("ic_action_search"))
    si.SearchView = sv
End Sub
- If the user presses the search menu item the ActionBar/Toolbar expands to an EditText view where he can enter his search text.
- If the user presses enter/submits the search the Search_QuerySubmitted (Query As String) event is called where you can handle the search. In this event sub you should Iconify the Searchview again:
B4X:
Sub Search_QuerySubmitted (Query As String)

    sv.Iconfied = True
    si.ItemCollapsed = True
   
   Do your search here.
End Sub
 
Upvote 0

Ramezanpour2

Member
Licensed User
Longtime User
It's better to ask each question in its own thread if they are not really related.

1: You have to change the theme xml file. See this or this answer on StackOverflow.

2: This is a bit like an undocumented feature. I never found the time to write a tutorial about it.

- Initialize the SearchView with an EventName
- Set it Iconified state by default sv.IconifiedByDefault = True
- You have to use the advanced menu. I usually set it up with some java code. si is of type ACMenuItem,
UIUtils.GetBitmapDrawable just loads a drawable. Just create a menu item and assign the searchview to it:
:
B4X:
#If Java

    public boolean _onCreateOptionsMenu(android.view.Menu menu) {
    if (processBA.subExists("activity_createmenu")) {
        processBA.raiseEvent2(null, true, "activity_createmenu", false, new de.amberhome.objects.appcompat.ACMenuWrapper(menu));
        return true;
    }
    else
        return false;
}
#End If

Sub Activity_CreateMenu(Menu As ACMenu)
    Menu.Clear
    si = Menu.Add2(1, 1, "Add location", UIUtils.GetBitmapDrawable("ic_action_search"))
    si.SearchView = sv
End Sub
- If the user presses the search menu item the ActionBar/Toolbar expands to an EditText view where he can enter his search text.
- If the user presses enter/submits the search the Search_QuerySubmitted (Query As String) event is called where you can handle the search. In this event sub you should Iconify the Searchview again:
B4X:
Sub Search_QuerySubmitted (Query As String)

    sv.Iconfied = True
    si.ItemCollapsed = True
  
   Do your search here.
End Sub





plesae add a sample source for this here thanks dear
 
Upvote 0

corwin42

Expert
Licensed User
Longtime User
Upvote 0

JohnC

Expert
Licensed User
Longtime User
This might be a stupid question, but using this code:

B4X:
Sub Activity_CreateMenu(Menu As ACMenu)
    sv.Initialize2("Search", sv.THEME_DARK)
    sv.IconifiedByDefault = True

    'Clear the menu
    Menu.Clear
       
    'Add a menu item and assign the SearchView to it
    si = Menu.Add2(1, 1, "Search", Null)
    si.SearchView = sv
   
    Menu.Add(2,0,"Test 1",Null)
    Menu.Add(3,0,"Test 2",Null)
End Sub

What would be the event sub_name to trap the selecting of "Test 1" or "Test 2" event?

I ask because it seems you are making the menu in Java using this code:

B4X:
'Inline Java code to initialize the Menu
#If Java
    public boolean _onCreateOptionsMenu(android.view.Menu menu) {
        if (processBA.subExists("activity_createmenu")) {
            processBA.raiseEvent2(null, true, "activity_createmenu", false, new de.amberhome.objects.appcompat.ACMenuWrapper(menu));
            return true;
        }
        else
            return false;
    }
#End If

But I can't easily see what the menu "name" is to know what the first part of the event name should be.

Any help would be greatly appreciated
 
Upvote 0

JohnC

Expert
Licensed User
Longtime User
I figured it out - I had to do a:
B4X:
ActionBar.InitMenuListener

Then the event sub name was:

B4X:
Sub ActionBar_MenuItemClick (Item As ACMenuItem)
    Log("ActionBar_MenuItemClick event fired, id:" & Item.Id)
End Sub
 
Upvote 0
Top