[英]How to set the Image and the Text at the center of Button in android
[英]How to set text of Image Button (Android)?
在我的Android項目中,我有一個圖像按鈕,其背景設置為某個圖像。 我想在圖像按鈕上設置一些文字。 我怎么做/
我想設置文本,因為本地化將在項目中使用....
ImageButton不應該有文本,這就是為什么它被稱為ImageButton。
嘗試使用Button ,它繼承自TextView並具有android:text屬性。
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="mail"
android:background="@drawable/btn_selector"/>
是否有任何特殊原因要使用ImageButton而不是Button?
而不是使用ImageButton,只需使用常規按鈕並使用drawable屬性。 有幾個取決於你想要的drawable的位置。
http://developer.android.com/reference/android/widget/TextView.html#attr_android:drawableBottom
我遇到了同樣的問題。 我通過在ImageButton下添加TextView並設置其Text來解決這個問題。 如果您使用了Button而嘗試將圖片設置為背景,則會在圖片中間找到文本並且不會顯而易見。 但是,通過這種方式,您將在文件名上方具有Windows圖標的形狀。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.