隐藏搜索视图关闭按钮

时间:2015-12-30 10:20:08

标签: android searchview

当在Android的默认SearchView时,我将iconifide设置为false,然后隐藏SearchView的关闭按钮。

要求: SearchView默认情况下应在Activity启动时打开,并且关闭按钮应该可见;

 searchView.setSearchableInfo(searchManager.getSearchableInfo(new ComponentName(this, SearchResultActivity.class)));
 searchView.setIconifiedByDefault(false);

1 个答案:

答案 0 :(得分:1)

第一种方法可以做到这一点

<!DOCTYPE html>

<html lang="en" ng-app="app">

<head>

<meta charset="utf-8"/>
<title>Environ</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta content="width=device-width, initial-scale=1.0" name="viewport"/>
    <meta http-equiv="Content-type" content="text/html; charset=utf-8">
    <meta content="" name="description"/>
    <meta content="" name="author"/>
    <!-- BEGIN GLOBAL MANDATORY STYLES -->

    <script src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=places,drawing"></script>
     <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700&subset=all" rel="stylesheet" type="text/css"/>

    <link href="static/assets/global/plugins/font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css"/>
    <link href="static/assets/global/plugins/simple-line-icons/simple-line-icons.min.css" rel="stylesheet" type="text/css"/>

    <link ng-href="static/assets/global/plugins/bootstrap/css/{{currentBootstrap}}" rel="stylesheet" type="text/css"/>

    <link href="static/assets/global/plugins/uniform/css/uniform.default.css" rel="stylesheet" type="text/css"/>
    <link href="static/assets/global/plugins/bootstrap-switch/css/bootstrap-switch.min.css" rel="stylesheet" type="text/css"/>

    <link href="static/assets/global/plugins/fancybox/source/jquery.fancybox.css"
     rel="stylesheet" type="text/css"/>
      <link rel="stylesheet" href="static/assets/global/css/selectize.css">
      <link rel="stylesheet" href="static/assets/global/css/clockface.css">
      <link rel="stylesheet" href="static/assets/global/css/bootstrap-datepicker3.css">
      <link rel="stylesheet" href="static/assets/global/css/bootstrap-switch.min.css">
      <link rel="stylesheet" href="static/assets/global/css/simple-line-icons.min.css">
      <link rel="stylesheet" href="static/assets/global/css/custom.css">
      <link rel="stylesheet" href="static/assets/global/css/dataTables.bootstrap.css">
    <link href="static/assets/global/plugins/bootstrap-toastr/toastr.min.css" rel="stylesheet" type="text/css"/>
    <link href="static/assets/global/css/daterangepicker-bs3.css" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="static/assets/global/plugins/angularjs/plugins/ui-select/select.min.css">
    <link id="ng_load_plugins_before"/>
    <link href="static/assets/admin/pages/css/inbox.css" rel="stylesheet" type="text/css"/>
    <link ng-href="static/assets/global/css/{{currentComponents}}" id="style_components" rel="stylesheet" type="text/css"/>
    <link ng-href="static/assets/global/css/{{currentPlugins}}" rel="stylesheet" type="text/css"/>
    <link ng-href="static/assets/admin/layout/css/{{currentLayout}}" rel="stylesheet" type="text/css"/>
    <link id="style_color" ng-href="static/assets/admin/layout/css/themes/{{currentDarkblue}}" rel="stylesheet" type="text/css"/>
    <link rel="stylesheet" type="text/css" href="static/assets/global/plugins/select2/select2.css"/>
    <link rel="stylesheet" type="text/css" href="static/assets/global/plugins/bootstrap-wysihtml5/bootstrap-wysihtml5.css">
    <link rel="stylesheet" type="text/css" href="static/assets/global/plugins/bootstrap-editable/bootstrap-editable/css/bootstrap-editable.css"/>
     <link ng-href="static/assets/admin/layout/css/{{currentCustom}}" rel="stylesheet" type="text/css"/>
    <!-- END THEME STYLES -->
    <link rel="shortcut icon" href="favicon.ico"/>
</head>

<body ng-class="{
    'login': $state.current.name.split('.')[0] === 'login',
    'page-header-fixed page-quick-sidebar-over-content': $state.current.name.split('.')[0] === 'home'
}" ui-view style="background-color:#2B3643;">

<!-- BEGIN PAGE SPINNER -->
<span us-spinner ng-spinner-bar></span>
<!-- END PAGE SPINNER -->

 <script src="static/js/lib/socket.js" type="text/javascript"></script>
 <script src="static/js/node-scripts.js" type="text/javascript"></script>
 <script src="first.min.js" type="text/javascript"></script>

<script type="text/javascript" src="second.min.js"></script>
<script type="text/javascript" src="static/js/lib/angular-translate.min.js"></script>
<script type="text/javascript" src="static/js/routes.js"></script>
<script type="text/javascript" src="static/js/config.js"></script>

<!-- Classes -->
<script src="node_modules/angular-spinner/node_modules/spinjs/spin.js"></script>
<script src="node_modules/angular-spinner/angular-spinner.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.js"></script>
<script type="text/javascript" src="static/js/classes.js"></script>
<script type="text/javascript" src="static/js/datatable.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.1.2/build/rollups/pbkdf2.js"></script>

<script type="text/javascript" src="models.controllers.min.js"></script>

<script src="third.min.js" type="text/javascript"></script>
<script src="fourth.min.js" type="text/javascript"></script>

</body>
<!-- END BODY -->
</html>

或者还有另一种方式

    SearchView searchView = (SearchView)  
    menu.findItem(R.id.action_search).getActionView();
    searchView.setIconifiedByDefault(true);
    searchView.setFocusable(true);
    searchView.setIconified(false);
    searchView.requestFocusFromTouch();

了解更多详情link-1link-1