znl_12
znl_12
采纳率85.4%
2012-12-26 05:23 阅读 32.7k
已结题

关于在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 06: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)

    点赞 5 评论 复制链接分享
  • happy423 happy423 2015-08-08 02: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;  
    

    }

    
    
    点赞 评论 复制链接分享

相关推荐