Android imagebutton with text

Source: Internet
Author: User

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>

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.