问题描述
我们都知道我们可以将setText(String)设置为editText框,但如果你想从字符串变量中获取可编辑变量,你怎么做?
We all know we can setText(String) to an editText box but if you want to get an editable variable from a string variable how do you do this?
对于Temp,我创建了一个不可见的editText框来设置然后从中获取将字符串转换为可编辑。
For Temp I made an invisible editText box to set to then get from which turns the string into editable.
re:我自己的引用String = editablevariable.getText() .toString()
re: for my own reference String again = editablevariable.getText().toString()
推荐答案
您可能已经发现,Editable是一个界面,因此您无法调用 new可编辑()
。
但是,Editable只不过是一个带有Spannables的String,所以请使用:
As you probably found out, Editable is an interface so you cannot call new Editable()
.
However an Editable is nothing more than a String with Spannables, so use SpannableStringBuilder:
Editable editable = new SpannableStringBuilder("Pass a string here");
如果您只想更改Spannables,从不文本本身,您可以使用基本的。
If you only want to change the Spannables, never the text itself, you can use a basic SpannableString.
这篇关于Android如何将字符串转换为可编辑的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!