/
SearchView.yml
187 lines (155 loc) Β· 6.5 KB
/
SearchView.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
---
name: Titanium.UI.Android.SearchView
summary: A specialized text field for entering search text.
description: |
| Android |
| ------- |
| ![Android](./searchview_android.png) |
`SearchView` provides a user interface to enter a search query and submit a request to a search provider.
Search views are most commonly used for filtering the rows in a [TableView](Titanium.UI.TableView).
Similar to [SearchBar](Titanium.UI.SearchBar), you can add a search view to a table view by setting the table view's
[search](Titanium.UI.TableView.search) property. A search view can be used without a `TableView`.
You can also use a `SearchView` object as the <Titanium.UI.ListView.searchView>
property of a [ListView](Titanium.UI.ListView) object.
You can also add `SearchView` to an `ActionBar` as a view (see example below).
Use the <Titanium.UI.Android.createSearchView> method or **`<SearchView>`** Alloy element to create
a search view. You must set the Alloy element's `ns` attribute to **Ti.UI.Android**:
``` xml
<SearchView ns="Ti.UI.Android" platform="android"/>
```
extends: Titanium.UI.View
excludes:
methods: [add]
since: "3.0.2"
platforms: [android]
methods:
- name: blur
summary: Causes the search view to lose focus.
- name: focus
summary: Causes the search view to gain focus.
events:
- name: blur
summary: Fired when the search view loses focus.
- name: cancel
summary: Fired when the cancel button is pressed.
description: |
Due to the current [Android Issue](http://code.google.com/p/android/issues/detail?id=25758), this event does not work
with Android 4.0+. Alternatively, when using SearchView in the action bar, you can listen for the [MenuItem.collapse](Titanium.Android.MenuItem.collapse) event.
- name: change
summary: Fired when the value of the search view changes.
- name: focus
summary: Fired when the search view gains focus.
- name: submit
summary: If the search query is not empty, fired when the search button is clicked on soft keyboard
properties:
- name: color
summary: Color of the text in this SearchView, as a color name or hex triplet.
description: |
For information about color values, see the "Colors" section of <Titanium.UI>.
type: String
- name: hintText
summary: Text to show when the search view field is not focused.
type: String
default: no hint text
- name: hintTextColor
summary: Color of hint text that displays when field is empty.
description: |
Color of hint text that displays when field is empty.
type: String
default: Default Android theme's hint text color.
since: 7.1.0
- name: value
summary: Value of the search view.
description: |
This value cannot be set until after the search view is created.
type: String
- name: iconified
summary: Iconifies or expands the search view
description: see [Android Documentation](https://developer.android.com/reference/android/widget/SearchView.html#setIconified(boolean)) for more details.
type: Boolean
default: undefined
- name: iconifiedByDefault
summary: Sets the default or resting state of the search view
description: see [Android Documentation](https://developer.android.com/reference/android/widget/SearchView.html#setIconifiedByDefault(boolean)) for more details.
type: Boolean
default: true
- name: submitEnabled
summary: Whether to display the submit button when necessary or never display.
type: Boolean
default: undefined
examples:
- title: Search View for Table in Action Bar
example: |
The following example creates a SearchView widget for a TableView
and displays it as an Action Bar item if the Google API level is 11 or later.
If not, it defaults to use the search bar.
``` js
var win = Ti.UI.createWindow({
fullscreen: false
});
// Use action bar search view
var search = Ti.UI.Android.createSearchView({
hintText: "Table Search"
});
win.activity.onCreateOptionsMenu = function(e) {
var menu = e.menu;
var menuItem = menu.add({
title: 'Table Search',
actionView : search,
icon: (Ti.Android.R.drawable.ic_menu_search ? Ti.Android.R.drawable.ic_menu_search : "my_search.png"),
showAsAction: Ti.Android.SHOW_AS_ACTION_IF_ROOM | Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
});
};
var data = [];
data.push(Ti.UI.createTableViewRow({title:'Apple'}));
data.push(Ti.UI.createTableViewRow({title:'Banana'}));
data.push(Ti.UI.createTableViewRow({title:'Orange'}));
data.push(Ti.UI.createTableViewRow({title:'Raspberry'}));
var tableview = Titanium.UI.createTableView({
data: data,
search: search,
searchAsChild: false
});
win.add(tableview);
win.open();
```
- title: Alloy XML Markup
example: |
Previous example as an Alloy project.
index.xml:
``` xml
<Alloy>
<Window id="win" backgroundColor="blue" fullscreen="false" layout="vertical">
<TableView id="tableview" top="10" searchAsChild="false">
<TableViewRow title="Apple" />
<TableViewRow title="Banana" />
<TableViewRow title="Orange" />
<TableViewRow title="Raspberry" />
</TableView>
</Window>
</Alloy>
```
index.js:
``` js
// use action bar search view
var search = Alloy.createController("searchview").getView();
$.tableview.search = search;
$.win.addEventListener("open", function() {
$.win.activity.onCreateOptionsMenu = function(e) {
e.menu.add({
title: "Table Search",
icon: (Ti.Android.R.drawable.ic_menu_search ? Ti.Android.R.drawable.ic_menu_search : "my_search.png"),
actionView: search,
showAsAction : Ti.Android.SHOW_AS_ACTION_ALWAYS | Ti.Android.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW
});
}
$.win.activity.invalidateOptionsMenu();
});
$.win.open();
```
searchview.xml:
``` xml
<Alloy>
<SearchView id="searchView" ns="Ti.UI.Android" platform="android" hintText="Table Search" />
</Alloy>
```