2 znl 12 znl_12 于 2012.12.26 13:23 提问

关于在TextView中设置DrawableLeft的问题

xml中的textView:

<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"/>

如程序中所见我在xml中设置了 DrawableLeft。
我想在代码中改变drawable。
有什么方法可以使用代码为textview设置drawableLeft呢?

2个回答

franzhong
franzhong   2012.12.26 14:04
已采纳
public void  setCompoundDrawables  (Drawable left, Drawable top, Drawable right, Drawable bottom);

类似调用方法如下:

1.在XML中使用
android:drawableLeft="@drawable/icon"
2.代码中动态变化
Drawable drawable= getResources().getDrawable(R.drawable.drawable);
/// 这一步必须要做,否则不会显示.
drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
myTextview.setCompoundDrawables(drawable,null,null,null);

也或参考另一个函数

public void setCompoundDrawablesWithIntrinsicBounds (Drawable left,
Drawable top, Drawable right, Drawable bottom)

happy423
happy423   2015.08.08 10:32

std::string CBC_CTS_AESEncryptStr(std::string sKey, std::string sIV, const char *plainText)
{
std::string outstr;

//填key  
SecByteBlock key(AES::MAX_KEYLENGTH);  
memset(key,0x30,key.size() );  
sKey.size()<=AES::MAX_KEYLENGTH?memcpy(key,sKey.c_str(),sKey.size()):memcpy(key,sKey.c_str(),AES::MAX_KEYLENGTH);  

//填iv  
byte iv[AES::BLOCKSIZE];  
memset(iv,0x30,AES::BLOCKSIZE); 
sIV.size()<=AES::BLOCKSIZE?memcpy(iv,sIV.c_str(),sIV.size()):memcpy(iv,sIV.c_str(),AES::BLOCKSIZE);

AES::Encryption aesEncryption((byte *)key, AES::MAX_KEYLENGTH);  

CBC_CTS_Mode_ExternalCipher::Encryption cbcctsEncryption(aesEncryption, iv);  

StreamTransformationFilter cbcctsEncryptor(cbcctsEncryption, new HexEncoder(new StringSink(outstr)));  
cbcctsEncryptor.Put((byte *)plainText, strlen(plainText));  
cbcctsEncryptor.MessageEnd();  

return outstr;  

}


Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!