没有人有教程来实现使用支持库v7(appcomat_v7)的片段中的CAB吗?上下文片段中的操作栏
我无法找到任何加上developer.android教程是不明确的。
这是我的代码到目前为止。我正在做一个简单的测试程序,当您选择列表中的项目时,会出现上下文操作栏,其中会显示像选择x项目之类的东西并显示删除按钮。
我想在一个片段中做到这一点,所以这里发布的所有代码都在一个片段内。
上下文酒吧XML文件
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:idk="http://schemas.android.com/apk/res-auto" >
<item
android:id="@+id/menu_delete"
android:icon="@android:drawable/ic_menu_delete"
android:orderInCategory="100"
idk:showAsAction="ifRoom|withText"
android:title="Delete"/>
</menu>
这是ActionMode.Callback接口的实现
private ActionMode.Callback mActionModeCallback = new ActionMode.Callback()
{
// Called when the user selects a contextual menu item
@Override
public boolean onActionItemClicked(ActionMode mode, MenuItem item)
{
// TODO Auto-generated method stub
switch(item.getItemId())
{
case R.id.menu_delete:
return true;
}
return false;
}
//// Called when the action mode is created; startActionMode() was called
@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu)
{
// TODO Auto-generated method stub
mode.getMenuInflater().inflate(R.menu.delete_only, menu);
return true;
}
// Called when the user exits the action mode
@Override
public void onDestroyActionMode(ActionMode mode)
{
// TODO Auto-generated method stub
mActionMode = null;
}
//// Called each time the action mode is shown. Always called after onCreateActionMode, but
// may be called multiple times if the mode is invalidated.
@Override
public boolean onPrepareActionMode(ActionMode mode, Menu menu)
{
// TODO Auto-generated method stub
return false;
}
};
这是对项目点击监听器列表视图
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id)
{
// TODO Auto-generated method stub
if(listItemSelections.contains(1) && mActionMode == null)
{
mActionMode = getActivity().startActionMode(mActionModeCallback);
}
}
这是给我的线他错误
mActionMode = getActivity().startActionMode(mActionModeCallback);
它说
The method startActionMode(ActionMode.Callback) in the type Activity is not applicable for the arguments (ActionMode.Callback)
林不知道该怎么做,我不能找到一个教程,说明片段内执行,并使用支持库。
谢谢您的阅读。
感谢,认为工作 – user3364963 2014-09-20 06:57:05
你总是欢迎参观。很高兴帮助你! – Piyush 2014-09-20 06:58:34
工具栏android的东西是abotu – Harsha 2016-08-26 07:12:37