DroidScript wiki

(was AndroidScript) unofficial documentation by the community

User Tools

Site Tools


sample_code:textedit_search

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
sample_code:textedit_search [2015/04/01 12:26]
stevegarman
sample_code:textedit_search [2015/08/05 06:40] (current)
octazid Add simple Sample
Line 1: Line 1:
 +====== Simple Custom Search Bar ======
 +
 +A simple custom search bar could be made up from a TextEdit control and a search button control, contained within a horizontal Linear Layout. The code below is a very simple quick implementation.
 +
 +<code javascript search.js>​
 +var txtSize = 22;
 +
 +//Called when application is started.
 +function OnStart()
 +{
 +    lay = app.CreateLayout( "​linear",​ "​FillXY"​ ); 
 +    lay.SetBackground( "/​Sys/​Img/​BlueBack.png"​ );
 + 
 +    //Create a layout to hold the search controls
 +    laySearch = app.CreateLayout( "​Linear",​ "​Horizontal,​ FillX, VCenter"​ ); 
 +    laySearch.SetBackColor( "#​000000"​ );
 +    laySearch.SetPadding( 0, 0.01, 0, 0.01 );
 + 
 +    //Create a TextEdit control for entering search text
 +    txeSearch = app.CreateTextEdit( "",​ 0.85 );
 +    txeSearch.SetTextSize( txtSize );
 + 
 +    //Create a search button
 +    btnSearch = app.CreateText( "​[fa-search]",​ 0.1, -1, "​FontAwesome"​ );
 +    btnSearch.SetTextSize( txtSize );
 +    btnSearch.SetOnTouch( btnSearch_OnTouch );
 + 
 +    laySearch.AddChild( txeSearch );
 +    laySearch.AddChild( btnSearch );
 +    lay.AddChild( laySearch );
 + 
 +    //Add layout to app. 
 +    app.AddLayout( lay );
 +}
 +
 +//Called when the search button is pressed
 +function btnSearch_OnTouch( ev )
 +{
 +    if( ev.action=="​Down"​ )
 +    {
 +        this.SetTextSize( txtSize-4 );
 +    }
 +    else if( ev.action=="​Up"​ ) 
 +    {
 +        this.SetTextSize( txtSize );
 +    
 +        var searchText = txeSearch.GetText();​
 +        app.ShowPopup( "​Search:​ " + searchText );
 +    }
 +}
 +</​code>​
 +//(Sample posted by Chris Hopkin in the Droidscript Forum)//
 +----
 +
 +
 ====== TextEdit Search ====== ====== TextEdit Search ======
 This function is designed to search for a string in a textEdit. This function is designed to search for a string in a textEdit.
sample_code/textedit_search.txt · Last modified: 2015/08/05 06:40 by octazid