如何在java文件中更改文本大小?

时间:2015-08-31 18:15:18

标签: android

如何更改java文件中的文字大小? 请回答我的问题.Thankyou

Xml文件:

<TextView
                android:id="@+id/txt1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_margin="10dp"
                android:gravity="center"
                android:text="@string/a"
                android:textColor="#000000"
                android:textDirection="rtl"
                android:textSize="40dp" />

3 个答案:

答案 0 :(得分:2)

这里有2个解决方案:

  1. 
   tv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 25); //dip or sp etc as you need

        OR
   2.

  txt1.setTextSize(TypedValue.COMPLEX_UNIT_PX, 
                   getResources().getDimension(R.dimen.result_font));

非常感谢

答案 1 :(得分:1)

试试这样:

txt1.setTextSize(15);

答案 2 :(得分:0)

使用setTextSize()在dp中设置值。