ActionBarSherlock(ABS):如何自定义动作方式接近项目的文字?自定义、动作、文字、方式

由网友(仙女味的猪)分享简介:我使用的是ABS VERS。 4,我需要简单地更改默认的完成,即除了动作模式关闭图标显示的文字,但我真的不知道如何做到这一点。I'm using ABS vers. 4 and I need to simply change the default "Done" text that is displayed besi...

我使用的是ABS VERS。 4,我需要简单地更改默认的完成,即除了动作模式关闭图标显示的文字,但我真的不知道如何做到这一点。

I'm using ABS vers. 4 and I need to simply change the default "Done" text that is displayed besides the action mode close icon, but I really can't figure out how to do it.

我认为文本需要定制,至少有两个很好的理由:

I think that text needs to be customizable for at least two good reasons:

完成并不适用于所有情况(例如,取消可能更合适,而且我已经看到了一些应用程序,如Galaxy Tab的我的文件的应用程序,使用它)

"Done" is not appropriate for all contexts (e.g. "Cancel" could be more appropriate, and I've seen some apps, such as the "My Files" app on Galaxy Tab, use it)

完成需要根据用户的语言来本地化

"Done" needs to be localized according to the user's language

是否有可能做自定义文本?如果是的话谁能告诉我该怎么办呢?

Is it possible to do customize that text? If so can anyone tell me how to do it?

在此先感谢。

修改

我已经找到了一个暂时的解决办法,我发布了以下内容:

I've found a temporary workaround, that I post in the following:

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。

That's the method I came up with. Please NOTE that it does heavily rely upon the structure of the abs__action_mode_close_item.xml of ABS 4.0.

这适用于我的情况,但是,正如你所看到的,它不能被认为是充分的满足,以促进它以一个真正的答案,这就是为什么我只修改我的previous职务。

This works for my scenario, but, as you can see, it cannot be considered sufficiently satisfying to promote it to a real "answer", that's why I only edited my previous post.

希望帮助别人,但我也希望有人可以共享一个更美好,更清洁的解决方案。

Hope that helps someone else, but I also hope that someone could share a better and cleaner solution.

推荐答案

您可以使用一个主题来覆盖默认图标:

You can use a theme to override the default icon:

    <item name="actionModeCloseDrawable">@drawable/navigation_back</item>
    <item name="android:actionModeCloseDrawable">@drawable/navigation_back</item>
阅读全文

相关推荐

最新文章