[英]How to change TextView to multi size in single texview
How to change my textview
size to multi sizes when I select sample in my layout texview
size should be change like this I need four different sizes, I google it I not found any solution for this so any please help me 如何改变我
textview
大小尺寸多,当我在我的布局中选择样本texview
大小应该是这样的变化,我需要四种不同尺寸,我谷歌,我没有发现这方面的任何解决方案,因此任何请帮助我
here below my screen short 这里我的屏幕短
onClick(event you want), you can change textsize of textview you want programatically onClick(您想要的事件),您可以以编程方式更改所需的textview的文本大小
EX: Do something like EX:做点什么
radioButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
text1.setTextSize(TypedValue.COMPLEX_UNIT_SP,14);
text2.setTextSize(TypedValue.COMPLEX_UNIT_SP,18);
text3.setTextSize(TypedValue.COMPLEX_UNIT_SP,22);
text4.setTextSize(TypedValue.COMPLEX_UNIT_SP,26);
}
});
Try this 尝试这个
you can save selected text size in shared preferece 您可以在共享首选项中保存选定的文本大小
public void showDialog()
{
final CharSequence[] items={"Use device font size","Tiny","Small","Normal","Huge"};
final CharSequence[] fontSize={"15","10","15","20","25"};
AlertDialog.Builder builder= new AlertDialog.Builder(this);
builder.setTitle("Font size");
builder.setPositiveButton("Cancel", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
int i= sharedpreference.getInt("position", 0) ;
builder.setSingleChoiceItems(items,i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
editor.remove("fontsize");
editor.remove("position");
editor.putFloat("fontsize",Float.parseFloat(fontSize[ which] .toString()));
editor.putInt("position", which);
editor.commit();
dialog.cancel();
}
});
builder.create();
builder.show();
}
and size of textview set dianamically 和textview的大小设置为dianamically
textview.setTextSize(sharedpreference.getFloat("fontsize", 15));
Hope this helps you 希望这对你有所帮助
Create a variable named int size = 12
; 创建一个名为
int size = 12
的变量;
Implement onClick event of Done
button of dialog interface and get which radio button is selected using if else ladder and set variable value to the size you want accordingly. 实现对话框界面的
Done
按钮的onClick事件,并使用if else梯形图选择哪个单选按钮,并将变量值设置为相应的大小。
then set this size to TextView
you want using text.setTextSize(size);
然后使用
text.setTextSize(size);
将此大小设置为您想要的TextView
text.setTextSize(size);
. 。
It works in my case. 它适用于我的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.