在EditText android中找到行尾(/ n)

时间:2013-10-09 10:28:28

标签: android android-edittext textview android-textattributes

我有一个edittext,我想在编辑文本的每一行上的文本之前附加一些字符,具体取决于按下的按钮。 例如

if( fivespacesbutton is pressed )
then
append five spaces on each line the function OnClick(View v) has called.

我想如果我了解行尾(/ n),那么我会在每行之前追加五个空格。

任何想法如何从

获得/ n
EditText scene=(EditText)findViewById(R.id.editText11);

1 个答案:

答案 0 :(得分:2)

String text = scene.getText().toString();
String result = "";
for (String line : text.split("\n"))
{
   result += "    " + line + "\n";
}
scene.setText(result);