2012-08-30 44 views
0

可拉伸標識具有可抽拉我想找到標識符如何從代碼

佈局

<TextView 
    ... 
    android:drawablePadding="5dp" 
    android:drawableLeft="@drawable/account_lock" 
/> 

活動

... 
TextView tv = ...; 
Drawable d = tv.getCompoundDrawables()[0]; 
int id = d.???????  

我已經看過getResources().getIdentifier(name, defType, defPackage),但我不認爲這有助於我找到它;

+1

我不認爲這是可能的 –

+0

我正好沒有得到這個問題,你可以請你ellaborate需要什麼?你想要左邊的drawable嗎? –

+0

我問我是否可以從Drawable對象獲取標識符 – pbaris

回答

0

這就是我已經做到的。儘管如此,我不知道是否需要將它放在res的子文件夾中。

//In this example, I'm getting an id from the res/raw folder. 
    int id = *activity.this*.getApplicationContext().getResources().getIdentifier(*filename*, "raw", *packagename*); 
1

ID應該是作爲R.drawable.account_lock訪問

+0

我問我是否可以將它從Drawable對象中取出,而不是從哪裏找到它 – pbaris