本文介绍了在一个TextView问题设置DrawableLeft的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我在XML一个TextView这里。

I have a textView in xml here.

<TextView
        android:id="@+id/bookTitle"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:drawableLeft="@drawable/checkmark"
        android:gravity="center_vertical"
        android:textStyle="bold"
        android:textSize="24dip"
        android:maxLines="1"

        android:ellipsize="end"/>

正如你可以看到我设置DrawableLeft的XML。

As you can see i set the DrawableLeft in xml.

我想改变code中的绘制。

I would like to change the drawable in code.

反正是有去这样做?或将drawableLeft在code文本视图??

Is there anyway to go about doing this? Or setting the drawableLeft in code for the text view??

推荐答案

您可以使用setCompoundDrawablesWithIntrinsicBounds(int左,INT顶部,诠释权,诠释底部)

设为0,你不想要的图像

set 0 where you don't want images

实例绘制对象左侧:

TextView textView = (TextView) findViewById(R.id.myTxtView);
textView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.icon, 0, 0, 0);


提示:当你知道任何XML属性,但没有线索如何使用它在运行时。刚去的财产的开发商文档的描述。在那里,你会发现相关方法如果它在运行时的支持。即For DrawableLeft


Tip: Whenever you know any XML attribute but don't have clue about how to use it at runtime. just go to the description of that property in developer doc. There you will find Related Methods if it's supported at runtime . i.e. For DrawableLeft

这篇关于在一个TextView问题设置DrawableLeft的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-08 19:08