android - Lollipop 之前的 ActionMode Material 主题

标签 android android-appcompat material-design android-actionmode

我在 Kitkat 4.4.2 设备中通过此代码显示 ActionMode,此代码来自 fragment targetSDK 21。我使用 Theme.AppCompat.Light.DarkActionBar 作为默认设置我的应用中的主题:

actionMode = getActivity().startActionMode(EventsFragment2.this);

ActionMode 显示为 Light Holo 主题小部件。所以我想也许 appcompat 库还不支持 ActionMode。但是,在同一个应用程序中,当在 EditText 中选择一些文本时, Material ActionMode 会显示所有精美的平面图标和动画。所以问题出在我的代码上。我在这里做错了什么?

注意:我也在使用 ActionBarActivity

最佳答案

答案比我想象的要简单,只需使用以下代码:

ActionBarActivity activity = (ActionBarActivity) getActivity();
actionMode = activity.startSupportActionMode(EventsFragment2.this);

确保您使用正确的导入,即..

import android.support.v7.view.ActionMode;

关于android - Lollipop 之前的 ActionMode Material 主题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26545972/

相关文章:

android - 错误 :(3, 5) 找不到与给定名称匹配的资源

android - 在 XML 中设置工具栏 Logo

Android Studio 需要在每次运行前重新构建项目

android - fragment 中的 ListView 使用 ArrayAdapter 未设置

android - 适用于 Android 的代理服务器 - 处理 HTTPS

android - 使用android.support.library时gradle同步失败

android - 为什么 android 中的 PJSip 无法正常工作?

android - onOptionsItemSelected 未调用

html - 使用materializecss显示与登录表单对齐的图像

android - 如何以编程方式将子菜单项添加到新的 Material 设计 android 支持库