将文本从原始文件复制到剪贴板

时间:2013-08-09 06:04:59

标签: java android textview clipboard

我有一个包含内容的原始文件:

Ah, dearest Jesus, holy Child,
make Thee a bed, soft, undefiled
within my heart, that it may be
a quiet chamber kept for Thee.

My heart for very joy doth leap,
My lips no more can silence keep;
I, too, must sing with joyful tongue
That sweetest ancient cradle song.

Glory to God in highest Heaven,
Who unto man His Son hath given;
While angels sing with tender mirth,
a glad new year to all the earth.
Amen.

当我使用TextView的setText方法时,它显示正常,但是当我使用以下代码将上述文本复制到剪贴板时,缺少新的行字符。如何解决它。

((ClipboardManager) getSystemService(CLIPBOARD_SERVICE))
                        .setText(tv.getText());

enter image description here

1 个答案:

答案 0 :(得分:1)

不幸的是,这似乎是对某些Android版本的反复抱怨,我还没有找到一个简单的解决方案。

话虽如此,我看到两种选择。第一种是尝试用\ n来替换新行字符,用于硬回车的Android字符。这可能会解决您的问题。

如果没有,您可能只想在每次硬回车之前放置一个空格,这样在复制时它就不会同时运行这些单词。希望你能搞定它!

相关问题