仅使用Kotlin更改textview的值,而不会影响默认大小

时间:2018-11-04 11:21:25

标签: android android-studio kotlin

我正在以编程方式更改textview的值。

XML:

 <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:id="@+id/name"
                android:text="test"
                android:textSize="45px"/>

科特琳:

   name.text = "John Doe"

但是,当我使用上述Kotlin代码时,textSize也将更改为默认值。

如何保留textSize="45px"

1 个答案:

答案 0 :(得分:0)

有2个选项。

第一个选择是,将div { text-align: center } .image1 { border: 15px solid seagreen; outline: 15px solid green; width:'150px'; height:'150px'; border-radius: 75% } .image2 { border: 15px solid seagreen; position: relative; right:25px; width:'150px'; height:'150px'; border-radius: 75% } 替换为px。 然后您的dp如下所示:

TextView

在第二个选项中,只需将<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:id="@+id/name" android:text="test" android:textSize="45dp"/> 添加到代码中。 然后您的MainActivity如下所示:

name.textSize= 45f
相关问题