Set search hint dynamically

后端 未结 7 1457
悲哀的现实
悲哀的现实 2021-02-08 04:38

Does anybody knows how to set android search dialog hint dynamically? T have try to do something like:




        
7条回答
  •  执念已碎
    2021-02-08 04:39

    I managed to do this with ABS using the OnActionExpandListener and a custom actionView, e.g.:

    menu.add("Search")
    .setActionView(R.layout.collapsible_edittext)
    .setOnActionExpandListener(new MenuItem.OnActionExpandListener()
    {
        @Override
        public boolean onMenuItemActionExpand(MenuItem item) {
            ((EditText) item.getActionView()).setHint("Your custom text here");
            return true;
        }
    
        @Override
        public boolean onMenuItemActionCollapse(MenuItem item) {
            return true;
        }
    });
    

    with collapsible_edittext.xml:

    
    

提交回复
热议问题