gpt4 book ai didi

android - 在 android 中向 Commonsware RichEditText 添加自定义控件

转载 作者:行者123 更新时间:2023-11-30 02:48:41 27 4
gpt4 key购买 nike

创建一个包含以下内容的 Activity

1)编辑文本(Commonsware RichEditText)

2) 带有以下按钮的工具栏

粗体、斜体、下划线、删除线、字体、居中对齐、左对齐、右对齐、两端对齐等

4) 一个保存按钮

用法:

用户输入文本并通过选择文本整体或部分进行编辑。效果应用于选定的文本。当用户在编辑器中完成编辑文本时,他单击保存按钮。一切都从 RichEditText 中读取并发送到数据库以供以后使用标签和 html 格式。我使用以下代码进行保存和检索。

Spanned s = Html.fromHtml("<i>Hi</i> There ! <b>how're you ?</b>");
et.setText(s);

//--save to string--
Editable e = et.getText();
String s2 = Html.toHtml(e);

//--restore from string--
Spanned s3 = Html.fromHtml(s2);
et.setText(s3);

来源:Copy to clipboard using commonsware cwac-richedit library

问题:

我必须将粗体、斜体、下划线、删除线、字体、居中对齐、左对齐、右对齐、两端对齐等应用到按钮中的选定文本 onClick()工具栏不同于操作栏按钮。当在 RichEditText 上方的布局中进行选择时,有什么方法可以将整个 View 显示在操作栏中?比如说 Horizo​​ntal LinearLayout 或一些自适应布局?

如果有人能告诉他如何通过单击按钮将任何一种效果添加到所选文本,那将非常有帮助。我看到了下面的方法,但不确定T值是多少。

myRichEditText.applyEffect(effect, value);

谢谢。

最佳答案

Is there any way I can place the entire view shown in the actionbar when selection is made in a layout above the RichEditText?

没有。您的工具栏需要位于主 UI 中,例如 RichEditText 小部件本身的上方。

It would be really helpfull if some one can tell he how to add any one effect to a selected text on click of a button.

引用 the documentation :

applyEffect() changes the current selection, applying or removing an effect (e.g., making the selection bold). The first parameter is the effect to apply (e.g., RichEditText.BOLD). The second parameter is the new value for the effect. Many effects take boolean values, so applyEffect(RichEditText.BOLD, true) would format the current selection as bold.

FWIW,我计划为 RichEditText 提供一个标准的工具栏选项,但我不太可能在今年秋天之前有机会这样做。

关于android - 在 android 中向 Commonsware RichEditText 添加自定义控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24592998/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com