如何在运行时更改所选文本的字体大小的EditText?字体大小、所选、文本、如何在

2023-09-06 07:13:37 作者:说话绕弯儿

我开发一个文本编辑器,我的应用程序,其中我想编辑文本的选定部分。我几乎用它做除了一个功能,即可以减小所选文本的大小。

I am developing a text editor for my application, in which i want to edit the selected portion of text. And i am almost done with it except one feature, that to decrease the size of selected text.

我可以增加大小,如: 文本= editor.getText(); text.setSpan(新RelativeSizeSpan(2F),开始,结束,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); editor.setText(文本);

I could increase the size like : text=editor.getText(); text.setSpan(new RelativeSizeSpan(2f), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); editor.setText(text);

但我坚持减小大小,如何文本的大小可以降低?

But i am stuck with decreasing the size, How the size of text can be decreased ?

推荐答案

尝试,你已经用于增加TEXTSIZE用code,如下图所示,其中编辑器是EditText上以同样的方式

try the same way as you have used for increase textsize used code as shown below where editor is EditText

 Spannable text=(Spannable)editor.getText(); 
 text.setSpan(new RelativeSizeSpan(0.2f), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);    
 editor.setText(text);

在RelativeSizeSpan我已经使用的 0.2F 作为将decrese你TEXTSIZE你可以使用什么都大小您需要accordinglly文字大小

in RelativeSizeSpan i have used 0.2f as a text size which will decrese your textsize you can use what ever size you need accordinglly