我正在使用 ABS 版本。4,我需要简单地更改除了动作模式关闭图标之外显示的默认“完成”文本,但我真的不知道该怎么做。
我认为文本需要自定义至少有两个充分的理由:
“完成”并不适用于所有上下文(例如“取消”可能更合适,我见过一些应用程序,例如 Galaxy Tab 上的“我的文件”应用程序,使用它)
“完成”需要根据用户的语言进行本地化
是否可以自定义该文本?如果是这样,谁能告诉我该怎么做?
提前致谢。
编辑
我找到了一个临时解决方法,我将其发布在以下内容中:
private TextView getActionModeCloseTextView() {
// ABS 4.0 defines action mode close button text only for "large" layouts
if ((getResources().getConfiguration().screenLayout &
Configuration.SCREENLAYOUT_SIZE_MASK) ==
Configuration.SCREENLAYOUT_SIZE_LARGE)
{
// retrieves the LinearLayout containing the action mode close button text
LinearLayout action_mode_close_button =
(LinearLayout) getActivity().findViewById(R.id.abs__action_mode_close_button);
// if found, returns its last child
// (in ABS 4.0 there is no other way to refer to it,
// since it doesn't have an id nor a tag)
if (action_mode_close_button != null) return (TextView)
action_mode_close_button.getChildAt(action_mode_close_button.getChildCount() - 1);
}
return null;
}
这就是我想出的方法。请注意,它在很大程度上依赖于abs__action_mode_close_item.xml
ABS 4.0 的结构。
这适用于我的场景,但是,正如您所看到的,将其提升为真正的“答案”还不够令人满意,这就是为什么我只编辑了我以前的帖子。
希望对其他人有所帮助,但我也希望有人可以分享更好,更清洁的解决方案。