2016-07-26 47 views
1

我是編程新手,我有一些ImageViews內容描述。 我只能使用ImageViews的內容描述來填充ImageViews一些特定的背景顏色。而且我不需要在這裏使用資源ID。 請幫幫我。我們可以根據內容描述填寫ImageView

這裏是我的樣品的ImageView

<ImageView 
android:id="@+id/iv" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:contentDescription="iv"/> 
+1

你的問題不清楚 – Jas

+0

你可以通過ID獲得資源ID – comeback4you

+0

你至少需要使用資源ID來聲明你的圖片vie ws in activity,那麼你可以通過使用這個id作爲getContentDescription來檢查內容描述,並根據你的需求進行比較和填充 – Vickyexpert

回答

0

1:你可以使用 「#...」,並使用Color.parseColor(ImageView.getContentDescription())

2:您可以通過 「SOURCENAME」

GETID
Resources res = getResources(); 
final String packageName = getPackageName(); 
int imageResId = res.getIdentifier("ic_launcher", "drawable", packageName); 
int imageResIdByAnotherForm = res.getIdentifier(packageName + ":drawable/ic_launcher", null, null); 

int musicResId = res.getIdentifier("test", "raw", packageName); 

int notFoundResId = res.getIdentifier("activity_main", "drawable", packageName);