以编程方式访问自定义视图的元素

时间:2018-11-19 16:03:29

标签: java android

我正在将第3方库用于android活动,该库: https://github.com/pavlospt/CircleView

我的活动中有此实现:

<com.github.pavlospt.CircleView
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:id="@+id/weather_result"
        android:layout_width="200dp"
        android:layout_height="200dp"
        app:cv_titleSubtitleSpace="40"
        app:cv_fillColor="@color/white"
        app:cv_strokeColorValue="@color/black"
        app:cv_backgroundColorValue="@color/black"
        app:cv_titleColor="@color/black"
        app:cv_titleSize="50dp"
        app:cv_titleText="30ºC"
        app:cv_subtitleSize="12dp"
        app:cv_subtitleText="clima"
        app:cv_subtitleColor="@color/black"
        android:layout_gravity="center_horizontal"/>

我的问题是我无法以编程方式更改app:cv_titleText =“30ºC”属性。

有人可以帮助我吗?谢谢!

3 个答案:

答案 0 :(得分:1)

setTitleText(string)在您的CirleView上。

答案 1 :(得分:1)

    ((CircleView)findViewById((R.id.weather_result))).setTitleText("your text here");

答案 2 :(得分:1)

您必须使用setTitleText("Your Text")

CircleView yourcircleview = (CircleView)findViewById(R.id.yourcircleview);
yourcircleview.setTitleText("Your Text");

如果使用的是片段,则必须将findViewByIdview一起使用。

赞:CircleView yourcircleview = (CircleView)view.findViewById(R.id.yourcircleview);