Set ImageButton text from the code?
In examples found on the net I saw that the text is set from XML file only. I need to attach the text from another View, and I tried to find any setter that I can use to set text to ImageButton. I didn't succeed. I even tried using this
<ImageButton
android:background="#ffffff"
android:text="setText()"
/>
hoping that I can use setText() in the code, but it did not work as well.
How ca开发者_开发百科n I set the text for ImageButton programmatically?
Thanks
PS. This is a custom ImageView which inheritsImageView. ImageButtons can't have text (or, at least, android:text isn't listed in its attributes). It looks like you need to use Button (and look at drawableTop or setCompoundDrawablesWithIntrinsicBounds(int,int,int,int)).
You cannot set text to ImageButton because it has no method as setText() or android:text property.
Here is workaround, using a Button and android:drawableTop / Left / Right or Bottom like this :
<Button android:layout_height="wrap_content"
android:drawableTop="@drawable/icon" android:text="Button"
android:layout_weight="1" android:layout_width="fill_parent"
android:textSize="11sp"
android:layout_margin="1sp" />
加载中,请稍侯......
精彩评论