Android的文本选择监听器 [英] Android Text Selection Listener

查看:266
本文介绍了Android的文本选择监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创造一个优美,分心无文本编辑器。
其中一个我真的想实现的功能是弹出与简单的文本格式的命令,如粗体,斜体,下划线,字体颜色和字体。

I'm trying to create a graceful, distraction-free text editor.
One of the features I really would like to implement is a pop-up with simple text formatting commands, such as bold, italic, underline, font color, and font face.

为了给你一个想法,这里是iOS中弹出的画面(很显然,这仅仅是个想法,我想创建一个自定义设计的弹出窗口。):

To give you an idea, here is a picture of the popup in iOS(Obviously, this is just the idea. I want to create a custom design for the popup):

我有几个问题:
1)是否有这样的东西作为一个文本选择监听器,或者一些等价?
2)我是否需要重写文本选择默认的Andr​​oid行动?
3)我将如何显示/创建这个弹出? (模糊的问题,我知道...)

I have a few questions:
1) Is there such thing as a text selection listener, or some equivalent?
2) Will I need to override the default android action for text selection?
3) How would I display/create this popup? (Vague question, I know...)

我刚开始在Java和Android的发展,但我已经创建了一些应用程序,并已经得到了它的窍门。

I am just starting out in Java and Android development, but I have already created a few apps and have gotten the hang of it.

推荐答案

您正在寻找这里的关键术语,以帮助您与您的研究,是 ActionMode ,只要你的目标是蜂窝状或更高版本。

The key term you're looking for here, to help you with your research, is ActionMode, provided that your target is honeycomb or newer.

借助 API文档(向下滚动到使用上下文操作模式)做解释的事情是确定的工作,一旦你找到你要找的内容,这是其使用的最大障碍,但你将需要做的基本上这是什么:

The API docs (scroll down to "using the contextual action mode) do an ok job of explaining things, once you find what you're looking for, which is the biggest barrier to their use, but basically what you're going to need to do is this:

  1. 设置你的的EditText 是可选择的(安卓textIsSelectable =真正的 setTextIsSelectable(真);
  2. 实施 ActionMode.Callback 接口,并提供自己的菜单项。
  1. set your EditText to be selectable (android:textIsSelectable="true" or setTextIsSelectable(true);
  2. Implement the ActionMode.Callback interface and provide your own menu items.

注:如上所述,这仅适用于API级别11+。如果你的目标早期的平台,得到了事件的文本选择要复杂得多。

NOTE: as mentioned above, this only works for API level 11+. If you're targeting earlier platforms, getting the events for text selection is much more complicated.

这篇关于Android的文本选择监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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