2012-07-15 26 views
0

我想在Android中將日曆圖標顯示爲按鈕。我創建了一個圖像按鈕,將日曆圖像應用於圖像按鈕

ImageButton DtPk = new ImageButton(this); 

我知道,圖像將作爲設定,

Drawable d = Drawable.createFromPath("@drawable/calendar"); 
DtPk.setBackgroundDrawable(d); 

但我在哪裏可以儲存的圖像在我的項目呢?如何。

回答

0

當創建項目時,您應該看到一個名爲「res」的文件夾,並在其中放置幾個​​不同的可繪製文件夾。將圖像放在名爲drawable-mdpi的圖像中。然後簡單做到以下幾點:

DtPk.setImageResource(R.drawable.calendar); 

這裏是另一個SO文章,解釋更多關於繪製文件夾:Drawable folders in res folder?

閱讀該文檔中稱爲位圖文件部分:http://developer.android.com/guide/topics/resources/drawable-resource.html

+0

雅它工作正常!謝謝。 – posteritysystem 2012-07-15 06:47:08

+0

@posteritysystem請接受答案:http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work :) – 2012-07-15 06:52:14