简体   繁体   English

Android ImageSpans in Codename One TextFields

[英]Android ImageSpans in Codename One TextFields

I am porting my Android app to iOS and I am using Codename One for that.我正在将我的 Android 应用程序移植到 iOS 并且为此使用代号一。

In my app an EditText can contain icons mixed with text.在我的应用程序中,EditText 可以包含与文本混合的图标。 It is accomplished with instructions like these:它是通过如下指令完成的:

MyImageSpan iconSpan=new MyImageSpan(activity, R.drawable.icon);

editText.getText().insert(caretPosition,CHAR);

editText.getText().setSpan(iconSpan,caretPosition,caretPosition+1,Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

then in other parts, spans have to be detected, if present, and it is performed like this:然后在其他部分,必须检测跨度(如果存在),并且执行如下:

Editable editable = editText.getText();
for (int i = 0; i < editable.length(); i = next) {

        // find the next span transition
        next = editable.nextSpanTransition(i, editable.length(), MyImageSpan.class);
        // get all spans in this range

        MImageSpan[] tempSpans = editable.getSpans(i, next, MyImageSpan.class);
        ...
        ...
//In my app that becomes really complex            
        ...
        ...
        ...
        ...

}

I tried to use this online tool:我尝试使用这个在线工具:

http://fontello.com/ http://fontello.com/

to manage icons like font glyphs, as it seems to be adviced by Codename One documentation.管理像字体字形这样的图标,因为它似乎是由 Codename One 文档建议的。

In fact I do not understand if it is possible to have spans with different fonts in an TextField in Codename One, and I do not know if I could find and manage them inside the TextField.事实上,我不明白是否有可能在 Codename One 的 TextField 中有不同 fonts 的跨度,我不知道是否可以在 TextField 中找到并管理它们。

But the most important thing is that the online tool to create fonts out of svg files did not work for me because some icons are reverted, others are broken or confused, others are tiny, depending on the saving format (eventually I saved in pure SVG format to avoid issues but it's the same).但最重要的是,从svg文件中创建fonts的在线工具对我不起作用,因为有些图标被还原了,有些图标被破坏或混淆了,其他的很小,取决于保存格式(最终我保存在纯ZCD946B34B3ZCD935A75C3ZA3008中)格式以避免问题,但它是相同的)。

What I am asking is how to handle the spans in the TextField in Codename One.我要问的是如何处理 Codename One 中 TextField 中的跨度。 It has not to be the same "way" but the result has to be the same.它不必是相同的“方式”,但结果必须相同。

This won't work.这行不通。 Rich text edit is something that's just too different between platforms and isn't universally available.富文本编辑在平台之间差异太大,而且并非普遍可用。 Since the edit component is implemented using native widgets it's very hard to consistently abstract something like this and effectively impossible.由于编辑组件是使用本机小部件实现的,因此很难始终如一地抽象出这样的东西,而且实际上是不可能的。

However, web tools solved that problem already and include some cross platform rich edit tools that work.然而,web 工具已经解决了这个问题,并且包括一些可以工作的跨平台富编辑工具。 You can just use one of those tools and embed a BrowserComponent in your app.您可以只使用其中一种工具并将BrowserComponent嵌入到您的应用程序中。 Then perform the rich editing within the browser component.然后在浏览器组件中执行丰富的编辑。

Back in the day we did it with CK editor , but this library is pretty out of date by now so I'm not sure how well it works.过去我们用CK editor做的,但是这个库现在已经过时了,所以我不确定它的工作情况如何。 It should be relatively easy to create something like this though.不过,创建这样的东西应该相对容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM