在一个TextView问题设置DrawableLeft [英] Setting DrawableLeft in a TextView problem

查看:105
本文介绍了在一个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??

推荐答案

您可以使用<一个href="http://developer.android.com/reference/android/widget/TextView.html#setCompoundDrawablesWithIntrinsicBounds%28int,%20int,%20int,%20int%29">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属性,但没有线索如何使用它在运行时。刚去的财产的开发商文档的描述。在那里,你会发现相关方法如果它在运行时的支持。即<一href="http://developer.android.com/reference/android/widget/TextView.html#attr_android%3adrawableLeft">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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆