Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在文本中用字母换行_Java_Android_Android Edittext - Fatal编程技术网

Java 在文本中用字母换行

Java 在文本中用字母换行,java,android,android-edittext,Java,Android,Android Edittext,如何在androidEditText中用字母换行,所以它变成了这样: Hello how to br eak by letters instead of word s 与此相反: Hello how to break by letters instead of words css中的模拟是wordbreak:break all 当然,文本是动态变化的。试试这个 //tmpString—要显示的字符串 //15-您希望根据您的要求更改的信件数量 int index = 0; StringB

如何在android
EditText
中用字母换行,所以它变成了这样:

Hello how to br
eak by letters
instead of word
s
与此相反:

Hello how to
break by 
letters
instead of 
words
css中的模拟是
wordbreak:break all

当然,文本是动态变化的。

试试这个 //tmpString—要显示的字符串

//15-您希望根据您的要求更改的信件数量

int index = 0;
StringBuffer finalString = new StringBuffer(); 
while (index < tmpString.length()) {
    finalString.append(tmpString.substring(index, Math.min(index + 15,tmpString.length()))+"\n");
    index += 15;
}
editText.setText(finalString);
int索引=0;
StringBuffer finalString=新的StringBuffer();
而(索引
它称为“文本对齐”或“文本对齐”,但在
Android
中,它不受支持,至少到目前为止是这样


如果您想要实现,有一种解决方案。它使用
WebView
并以
HTML
格式加载文本,并将
body
样式设置为
justify
。如果您确实需要“文本对齐”,这只是一个解决方案。

您可以使用具有以下属性的自动调整编辑文本大小:

android:inputType="textMultiLine"
android:layout_height="wrap_content"
全文布局示例:

<EditText
   android:layout_width="match_parent"
   android:inputType="textMultiLine"
   android:layout_height="wrap_content"
   android:hint="Enter Text"
   android:textColorHint="@color/primary_color"
   android:ems="10"
   android:imeOptions="actionDone"
   android:id="@+id/message_input"
   android:layout_gravity="center_horizontal"/>