1

我要实现的这些选项对我的EditText 1:如何通过弹出菜单替换操作栏?

  • 替换由弹出菜单,而不是在顶部出现在动作条。事情是这样的为例:

enter image description here

  • ,或使动作条浮动和我目前的看法的孩子(以某种方式同第一选项)

我需要这个,因为我通过windowManager.addView(view,Layout_Params)添加我的视图;并以这种方式,我有一些麻烦,在顶部的动作条(它显示为空白)

其实我这样做,显示动作条:

@Override 
public ActionMode startActionMode(ActionMode.Callback callback) { 
    Activity host = (Activity) this.getContext();  
    return host.getWindow().getDecorView().startActionMode(callback); 
} 

,但它不工作,这是给我一个空的白色操作栏在停止,而不是:(我认为我需要创建自己的ActionMode,但我不知道该怎么做它

回答

0

好吧,当你的edittext获得焦点时,你可以隐藏操作栏。需要在任何你想要的地方弹出菜单

EditText t = new EditText(this); 
    t.setOnFocusChangeListener(new View.OnFocusChangeListener() { 
     @Override 
     public void onFocusChange(View view, boolean b) { 
      if(b){ 
       getSupportActionBar().hide(); 
       //now show your popup menu at the top position 
      }else{ 
       getSupportActionBar().show(); 
       //here you dismiss the menu. 
      } 

     } 
    });