There are two implementation methods for imagebutton with text in Android:
As follows:
Implementation 1:
<Linearlayout
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: Orientation = "vertical"
Android: Id = "@ + ID/BT">
<Imageview
Android: Id = "@ + ID/IB"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/ringlove"
Android: Background = "#00000000"
/>
<Textview
Android: Id = "@ + ID/TV"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "ssss"
/>
</Linearlayout>
Package com. oschina. test;
Import Android. App. activity;
Import Android. Graphics. color;
Import Android. OS. Bundle;
Import Android. View. motionevent;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. View. View. ontouchlistener;
Import Android. widget. linearlayout;
Import Android. widget. Toast;
Public class mainactivity extends activity {
Linearlayout m_ll;
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. Main );
M_ll = (linearlayout) findviewbyid (R. Id. bt );
M_ll.setclickable (true );
M_ll.setonclicklistener (OCl );
M_ll.setontouchlistener (OTL );
}
Public onclicklistener OCL = new onclicklistener (){
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Toast. maketext (getapplicationcontext (), "yes", Toast. length_short). Show ();
}
};
Public ontouchlistener OTL = new ontouchlistener (){
@ Override
Public Boolean ontouch (view V, motionevent event ){
// Todo auto-generated method stub
If (event. getaction () = motionevent. action_down)
{
M_ll.setbackgroundcolor (color. RGB (127,127,127 ));
}
Else if (event. getaction () = motionevent. action_up)
{
M_ll.setbackgroundcolor (color. Transparent );
}
Return false;
}
};
}
Implementation 2:
<Framelayout
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
>
<Imagebutton
Android: Id = "@ + ID/yugao"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: src = "@ drawable/btn_yugao"
Android: Background = "#00000000"
Android: layout_gravity = "center"
/>
<Textview
Android: Id = "@ + ID/yugao_label"
Android: layout_width = "wrap_content"
Android: layout_height = "wrap_content"
Android: text = "aaaaaa"
Android: textcolor = "@ color/blue"
/>
</Framelayout>