- mongodb - 在 MongoDB mapreduce 中,如何展平值对象?
- javascript - 对象传播与 Object.assign
- html - 输入类型 ="submit"Vs 按钮标签它们可以互换吗?
- sql - 使用 MongoDB 而不是 MS SQL Server 的优缺点
我刚刚将我的一个应用程序调整为新的 v22.1.1 支持和 appcompat 库,请参阅 here和 here更多细节。当我进行一些测试时,ActionModes 出现了问题。我正在使用。
当您启动 ActionMode使用 startSupportActionMode()
调用 - 是否使用现已弃用的 ActionBarActivity 并不重要基类或新的AppCompatActivity基类 - onPrepareActionMode()
未被调用。
在以前的版本中,包括 v21.0.3 和 v22.0.0,当最初使用 startSupportActionMode()
创建 ActionMode 时,会自动调用 onPrepareActionMode()
。
我在 2.2、4.4.2 和 5.0 设备上对其进行了测试,所以它似乎与版本无关。
有谁知道,如果这是预期的行为,这是在 v22.1.1 中引入的,还是一个错误?
我找到了 issue ,但是这里没有太多反馈...
2015 年 5 月 11 日编辑:
如 Android issue tracker 159527 中所述,这个问题不仅影响appcompat的v22.1.x和支持库,还影响5.1的Android实现。
目前有两种可能的临时解决方案,一种通用的:
@Override
public ActionMode startSupportActionMode(final ActionMode.Callback callback) {
// Fix for bug https://code.google.com/p/android/issues/detail?id=159527
final ActionMode mode = super.startSupportActionMode(callback);
if (mode != null) {
mode.invalidate();
}
return mode;
}
还有一个“又快又脏”的(当你实例化你的 ActionMode 时):
final ActionMode actionMode = startSupportActionMode(new MyActionMode());
if(actionMode != null) {
actionMode.invalidate();
}
如果你不使用 appcompat (ActionBarActivity
/AppCompatActivity
) 你需要用 startActionMode() 替换
.startSupportActionMode()
不幸的是,目前尚不清楚这是有意的新行为还是错误。根据API doc这是一个错误/回归,但谁知道...
最佳答案
我创建了一个演示,它工作正常,每次显示 Action 模式时都会调用 onPrepareActionMode。总是在 onCreateActionMode 之后调用,但是如果模式无效,可能会被多次调用。[我请求任何人进行小修改。我需要与工具栏颜色相同但动态的状态栏颜色,您可以看到不必要的 Drawyer 布局用于实现此效果,但是如果我删除 drawyer 布局,状态栏颜色不会根据工具栏颜色而改变。在实用程序中,默认情况下您可以看到默认主题颜色为红色,工具栏最初变为红色,但状态栏不会,仅当我删除 drawyer 布局时。我需要使用样式来做到这一点。]创建资源布局并命名 => action_mode_activity
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/my_drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:orientation="vertical"
app:insetForeground="#4000">
<include
android:id="@+id/toolbar"
layout="@layout/toolbar" />
<EditText
android:id="@+id/editTextCopy"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:layout_marginTop="19dp"
android:ems="10"
android:inputType="textMultiLine"
android:text="Long click to share!">
<requestFocus />
</EditText>
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
创建一个Activity,命名为ActionModeActivity
import android.os.Build;
import android.os.Bundle;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.ActionMode;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.example.deepakpawar.demolearning.R;
import com.example.deepakpawar.demolearning.demo.load.recycler.Utils;
/**
* Created by Deepak Pawar on 9/24/2015.
*/
public class ActionModeActivity extends AppCompatActivity implements View.OnLongClickListener, ActionMode.Callback {
EditText editTextCopy;
android.view.ActionMode mActionMode;
private Toolbar toolbar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Utils.onActivityCreateSetTheme(this);
setContentView(R.layout.action_mode_activity);
// 1. Get the editText
editTextCopy = (EditText) findViewById(R.id.editTextCopy);
// 2. add long-click listener
editTextCopy.setOnLongClickListener(this);
toolbar = (Toolbar) findViewById(R.id.toolbar);
if (toolbar != null) {
setSupportActionBar(toolbar);
ActionBar actionBar = getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setTitle("Android Students");
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
}
@Override
public boolean onLongClick(View view) {
// if actionmode is null "not started"
if (mActionMode != null) {
return false;
}
// Start the CAB
mActionMode = this.startActionMode(this);
view.setSelected(true);
return true;
}
// 4. Called when the action mode is created; startActionMode() was called
@Override
public boolean onCreateActionMode(android.view.ActionMode mode, Menu menu) {
// Inflate a menu resource providing context menu items
MenuInflater inflater = mode.getMenuInflater();
inflater.inflate(R.menu.action_menu, menu);
return true;
}
// 5. Called when the user click share item
@Override
public boolean onActionItemClicked(android.view.ActionMode mode, MenuItem item) {
switch (item.getItemId()) {
case R.id.action_share:
Toast.makeText(this, "Shared!", Toast.LENGTH_SHORT).show();
mode.finish(); // Action picked, so close the CAB
return true;
default:
return false;
}
}
// 6. 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(android.view.ActionMode mode, Menu menu) {
Toast.makeText(ActionModeActivity.this,"onPrepareActionMode Called ",Toast.LENGTH_SHORT).show();
return false; // Return false if nothing is done
}
// 7. Called when the user exits the action mode
@Override
public void onDestroyActionMode(android.view.ActionMode mode) {
mActionMode = null;
}
}
//具有改变主题的方法的Utils类//我创建它是因为需要动态更改应用程序主题导入android.app.Activity;
public class Utils {
private static int sTheme;
public final static int THEME_DEFAULT = 0;
public final static int THEME_WHITE = 1;
public final static int THEME_BLUE = 2;
/**
* Set the theme of the Activity, and restart it by creating a new Activity of the same type.
*/
public static int getsTheme() {
return sTheme;
}
public static void changeToTheme(Activity activity, int theme) {
sTheme = theme;
activity.recreate();
// activity.finish();
// activity.startActivity(new Intent(activity, activity.getClass()));
}
/**
* Set the theme of the activity, according to the configuration.
*/
public static void onActivityCreateSetTheme(Activity activity) {
switch (sTheme) {
default:
case THEME_DEFAULT:
activity.setTheme(R.style.FirstTheme);
break;
case THEME_WHITE:
activity.setTheme(R.style.SecondTheme);
break;
case THEME_BLUE:
activity.setTheme(R.style.Thirdheme);
break;
}
}
}
v21-themes.xml
<resources>
<style name="AppTheme" parent="AppTheme.Base">
<item name="android:windowContentTransitions">true</item>
<item name="android:windowAllowEnterTransitionOverlap">true</item>
<item name="android:windowAllowReturnTransitionOverlap">true</item>
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
<item name="android:actionOverflowButtonStyle">@style/Widget.ActionButton.Overflow</item>
<!-- <item name="android:navigationBarColor">@color/PrimaryColor</item>-->
<item name="windowActionBar">false</item>
<item name="windowActionModeOverlay">true</item>
<!-- To Make Navigation Drawer Fill Status Bar and become Transparent Too -->
<item name="android:windowDrawsSystemBarBackgrounds">true</item>
<item name="android:statusBarColor">@android:color/transparent</item>
<!--//if darker status bar needed-->
<!-- <item name="android:windowTranslucentStatus">true</item>-->
</style>
<style name="AppTheme.Base" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/PrimaryColor</item>
<item name="colorPrimaryDark">@color/PrimaryDarkColor</item>
<item name="colorAccent">@color/AccentColor</item>
<item name="android:textColorPrimary">@color/TextPrimaryColor</item>
<item name="android:windowBackground">@color/WindowBackground</item>
</style>
<style name="Widget.ActionButton.Overflow" parent="@android:style/Widget.Holo.ActionButton.Overflow">
<item name="android:contentDescription">@string/accessibility_overflow</item>
</style>
<!-- style for the tool bar backgrounds -->
<style name="ToolBarStyle" parent="ToolBarStyle.Base" />
<style name="ToolBarStyle.Base" parent="">
<item name="popupTheme">@style/ThemeOverlay.AppCompat.Light</item>
<item name="theme">@style/ThemeOverlay.AppCompat.Dark.ActionBar</item>
</style>
<style name="ToolBarStyle.Event" parent="ToolBarStyle">
<item name="titleTextAppearance">@style/TextAppearance.Widget.Event.Toolbar.Title</item>
</style>
<style name="TextAppearance.Widget.Event.Toolbar.Title" parent="TextAppearance.Widget.AppCompat.Toolbar.Title">
<!--Any text styling can be done here-->
<item name="android:textStyle">normal</item>
<item name="android:textSize">18sp</item>
<item name="android:textColor">#000000</item>
</style>
<!-- Customize your theme example here. -->
<style name="FirstTheme">
<item name="android:textColor">#FF0000</item>
<item name="colorPrimary">#FF0000</item>
<item name="colorPrimaryDark">#ff0000</item>
<item name="colorAccent">#ff0087</item>
<item name="android:shadowColor">#00ccff</item>
<item name="android:shadowRadius">1.5</item>
<item name="android:shadowDy">1</item>
</style>
<style name="SecondTheme">
<item name="android:textColor">#00FF00</item>
<item name="colorPrimary">#00FF00</item>
<item name="colorPrimaryDark">#00FF00</item>
<item name="colorAccent">#00FF90</item>
<item name="android:shadowColor">#00ccff</item>
<item name="android:shadowRadius">1.5</item>
<item name="android:shadowDy">1</item>
</style>
<style name="Thirdheme">
<item name="android:textColor">#0000F0</item>
<item name="colorPrimary">#0000F0</item>
<item name="colorPrimaryDark">#0000F0</item>
<item name="colorAccent">#0090F0</item>
<item name="android:shadowColor">#00ccff</item>
<item name="android:shadowRadius">1.5</item>
<item name="android:shadowDy">1</item>
</style>
<style name="AppCompatAlertDialogStyle" parent="Theme.AppCompat.Light.Dialog.Alert">
<item name="colorAccent">#FFCC00</item>
<item name="android:textColorPrimary">#FFFFFF</item>
<item name="android:background">#5fa3d0</item>
</style>
</resources>
关于android - 创建 ActionMode 时未调用 onPrepareActionMode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29927534/
为了让我的代码几乎完全用 Jquery 编写,我想用 Jquery 重写 AJAX 调用。 这是从网页到 Tomcat servlet 的调用。 我目前情况的类似代码: var http = new
我想使用 JNI 从 Java 调用 C 函数。在 C 函数中,我想创建一个 JVM 并调用一些 Java 对象。当我尝试创建 JVM 时,JNI_CreateJavaVM 返回 -1。 所以,我想知
环顾四周,我发现从 HTML 调用 Javascript 函数的最佳方法是将函数本身放在 HTML 中,而不是外部 Javascript 文件。所以我一直在网上四处寻找,找到了一些简短的教程,我可以根
我有这个组件: import {Component} from 'angular2/core'; import {UserServices} from '../services/UserService
我正在尝试用 C 实现一个简单的 OpenSSL 客户端/服务器模型,并且对 BIO_* 调用的使用感到好奇,与原始 SSL_* 调用相比,它允许一些不错的功能。 我对此比较陌生,所以我可能会完全错误
我正在处理有关异步调用的难题: 一个 JQuery 函数在用户点击时执行,然后调用一个 php 文件来检查用户输入是否与数据库中已有的信息重叠。如果是这样,则应提示用户确认是否要继续或取消,如果他单击
我有以下类(class)。 public Task { public static Task getInstance(String taskName) { return new
嘿,我正在构建一个小游戏,我正在通过制作一个数字 vector 来创建关卡,该数字 vector 通过枚举与 1-4 种颜色相关联。问题是循环(在 Simon::loadChallenge 中)我将颜
我有一个java spring boot api(数据接收器),客户端调用它来保存一些数据。一旦我完成了数据的持久化,我想进行另一个 api 调用(应该处理持久化的数据 - 数据聚合器),它应该自行异
首先,这涉及桌面应用程序而不是 ASP .Net 应用程序。 我已经为我的项目添加了一个 Web 引用,并构建了各种数据对象,例如 PayerInfo、Address 和 CreditCard。但问题
我如何告诉 FAKE 编译 .fs文件使用 fsc ? 解释如何传递参数的奖励积分,如 -a和 -target:dll . 编辑:我应该澄清一下,我正在尝试在没有 MSBuild/xbuild/.sl
我使用下划线模板配置了一个简单的主干模型和 View 。两个单独的 API 使用完全相同的配置。 API 1 按预期工作。 要重现该问题,请注释掉 API 1 的 URL,并取消注释 API 2 的
我不确定什么是更好的做法或更现实的做法。我希望从头开始创建目录系统,但不确定最佳方法是什么。 我想我在需要显示信息时使用对象,例如 info.php?id=100。有这样的代码用于显示 Game.cl
from datetime import timedelta class A: def __abs__(self): return -self class B1(A):
我在操作此生命游戏示例代码中的数组时遇到问题。 情况: “生命游戏”是约翰·康威发明的一种细胞自动化技术。它由一个细胞网格组成,这些细胞可以根据数学规则生存/死亡/繁殖。该网格中的活细胞和死细胞通过
如果我像这样调用 read() 来读取文件: unsigned char buf[512]; memset(buf, 0, sizeof(unsigned char) * 512); int fd;
我用 C 编写了一个简单的服务器,并希望调用它的功能与调用其他 C 守护程序的功能相同(例如使用 ./ftpd start 调用它并使用 ./ftpd stop 关闭该实例)。显然我遇到的问题是我不知
在 dos 中,当我粘贴此命令时它会起作用: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://google.
在 dos 中,当我粘贴此命令时它会起作用: "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" https://google.
我希望能够从 cmd 在我的 Windows 10 计算机上调用 python3。 我已重新安装 Python3.7 以确保选择“添加到路径”选项,但仍无法调用 python3 并使 CMD 启动 P
我是一名优秀的程序员,十分优秀!