ActionBarSherlock(ABS):如何自定义动作方式接近项目的文字? [英] ActionBarSherlock (ABS): how to customize the text of action mode close item?

查看:75
本文介绍了ActionBarSherlock(ABS):如何自定义动作方式接近项目的文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是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>

这篇关于ActionBarSherlock(ABS):如何自定义动作方式接近项目的文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆