如何將圖像添加到按鈕而不是文本?如何在android中添加按鈕圖片?
回答
相當幽默,考慮到您的標籤,只需使用ImageButton
小部件即可。
正如他所說,使用了ImageButton
小部件。將您的圖像文件複製到項目的Res/drawable/
目錄中。在XML中,只需進入XML文件的圖形表示(爲了簡單起見),然後單擊您添加的ImageButton
小部件,然後轉至其屬性頁並單擊src:
字段中的[...]。只需導航到您的圖像文件。另外,請確保您使用的是正確的格式;由於我自己的原因,我傾向於堅持使用.png文件,但它們工作正常。
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="News Feed"
android:icon="@drawable/newsfeed" />
新聞源則在繪製文件夾
這不起作用。 爲了使按鈕出現的文本和圖標,則使用按鈕類與機器人:drawableLeft屬性: '<按鈕 機器人:layout_width =「WRAP_CONTENT」 機器人:layout_height =「WRAP_CONTENT」 機器人:text =「@ string/button_text」 android:drawableLeft =「@ drawable/button_icon」>' – 2013-02-24 17:25:09
對不起,我的後期重播,但它適用於我 你不分配文本的按鈕,所以它不會出現 和問題是顯示按鈕與圖像,而不是文本:) – 2014-10-14 09:50:31
形象你應該嘗試這樣
<Button
android:id="@+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/qrcode"/>
的android:background="@drawable/qrcode"
東西會做
[ImageButton](https://developer.android.com/refe rence/android/widget/ImageButton.html)在使用'wrap_content'時總是選擇正確的大小。 「按鈕」可以扭曲圖像,特別是當它們很小時。 – Chilloutman 2016-07-29 16:19:00
把你的形象繪製文件夾中。在這裏我的圖像文件名left.png
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_x="118dp"
android:layout_y="95dp"
android:background="@drawable/left"
android:onClick="toast"
android:text=" " />
只需使用ImageButton的查看和設置圖片吧:`
<ImageButton
android:id="@+id/searchImageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@android:drawable/ic_menu_search" />
你可以在你的Android activity_main.xml中創建的ImageButton和圖像你想放置在您的按鈕只是將該圖像粘貼到您的可繪製文件夾下面是示例代碼供您參考。
<ImageButton
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="49dp"
android:layout_weight="1"
android:onClick="prev"
android:src="@drawable/prev"
/>
- 1. android:如何添加圖片按鈕?
- 2. 如何在按下按鈕後在applet(java)中添加圖片?
- 3. 如何在android中添加按鈕?
- 4. 如何在android中添加按鈕?
- 5. 在按鈕上添加圖片
- 6. 如何在Jquery Mobile按鈕中添加圖片?
- 7. 如何在片段佈局上添加按鈕?(Google maps Android studio)
- 8. Android:如何在表面視圖中添加按鈕
- 9. 如何在Android中的圖像按鈕下添加文本?
- 10. 如何在每個Android活動中添加圖像按鈕?
- 11. 如何添加背景圖片到pygame gui中的按鈕?
- 12. 在片段中添加一個按鈕?
- 13. 將圖片添加到按鈕
- 14. 添加URL圖片按鈕點擊
- 15. 從按鈕中添加圖片庫中的圖片並在按鈕上顯示照片
- 16. 如何在Outlook中爲自定義按鈕添加圖片圖標
- 17. 在按下按鈕時在TableView單元格上添加圖片
- 18. android - 圖片旋轉在圖像按鈕
- 19. 的Android添加圖片到ListViewItem的點擊按鈕
- 20. 在Android中添加圖片視圖
- 21. Android - 圖片按鈕大小
- 22. android - 如何在單選按鈕旁邊添加視圖
- 23. Android:如何在列表視圖底部添加提交按鈕
- 24. 如何爲android按鈕添加陰影
- 25. 如何添加MapView上的按鈕android
- 26. C#如何在按鈕陣列按鈕上添加圖像
- 27. 如何在離子卡片頭中添加摺疊按鈕?
- 28. 如何在JavaFX中按一下按鈕以添加圖像
- 29. 如何在Android中設置網頁圖片按鈕資源?
- 30. 在Android中,如何讀取當前按鈕的背景圖片?
實際上有幫助的回覆,謝謝!我不知道在哪裏放置圖像或如何指定它們的位置。 – hubatish 2016-02-16 18:56:15