1


我想将 SearchView 添加到另一个视图。我无法将其放置到 ActionBar(我隐藏本机 actionBar 并改为创建自定义视图)。
当我将它添加到 View 并将search:searchBar设置为 TableView 时,我的应用程序崩溃了。
我使用 Appcelerator Studio,平台是 Android

这是我使用的代码:

var searchBar = Ti.UI.createSearchBar({
    hintText:"",  
    color:"#000000",  
    barColor:"#eaeaea",  
    height:40,  
    borderColor:"#ffffff",  
    backgroundColor:"#ffffff",  
    showCancel:false  
}); 
var prevadzkyListView = Ti.UI.createListView({
top:55, 
templates:{'simple':cTemplate},
separatorStyle:1,
width:width,
height:height-80,
backgroundColor: 'transparent',
editing: false,
moving: false,
visible: true,
scrollable:true,
searchView:searchBar,
resultsBackgroundColor: "#c0392b",

});

4

1 回答 1

0

在您的布局 XML 中添加以下内容:

   <SearchView
            android:id="@+id/searchView"
            android:layout_width="match_parent"
            android:elevation="2dp"
            android:background="#fff"
            android:layout_height="wrap_content"> 
        </SearchView>

在您的 java 活动类中添加以下内容:

searchView = (SearchView) findViewById(R.id.searchView);
        searchView.setQueryHint("Search View");   
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
            @Override
            public boolean onQueryTextSubmit(String query) {
                Toast.makeText(getBaseContext(), query, Toast.LENGTH_LONG).show();
                return false;
            }

            @Override
            public boolean onQueryTextChange(String newText) {
                Toast.makeText(getBaseContext(), newText, Toast.LENGTH_LONG).show();
                return false;
            }
        });

注意import android.widget.SearchView;

于 2016-10-06T05:09:16.553 回答