在我的应用中,有一个textview。 textview中填充了数据库中的数据。以下是textview的XML
android:id="@+id/ViewMessageOne"
android:layout_width="275dp"
android:layout_height="45dp"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
android:textSize="14sp"
android:typeface="sans"
android:background="@drawable/back"
android:layout_marginLeft="35dp"
/>
以下是从DB
填充textview中数据的代码行final TextView ViewMessageOne = (TextView) findViewById(R.id.ViewMessageOne);
ViewMessageOne.setText(Html.fromHtml(getMessages("MSG_ONE")+ "<br>" + "<small>" + getTimeStamp("MSG_ONE") + "</small>"));
当填充来自DB的数据时,屏幕中的文本大小很小,并且没有采用XML值。我通过增加textview文本的大小来检查这一点。但它没有从XML中获取文本大小。任何人都可以指导我如何从XML获取文本大小值的值,从而使用JAVA代码实现它。谢谢
答案 0 :(得分:0)
您的代码中有以下行:
android:textAppearance="?android:attr/textAppearanceMedium"
可能会覆盖您的自定义文本大小 删除该行并重试
编辑:以编程方式设置文字大小:
viewMessageOne.setTextSize(16)
答案 1 :(得分:0)
更改此
android:layout_height="45dp"
到这个
android:layout_height="wrap_content"