Mono custom image button and mono Custom button

Source: Internet
Author: User

Mono custom image button and mono Custom button

First, we compile a MyImageButton class that inherits from LinearLayout.

Public class MyPhoneImageButton: LinearLayout {private ImageView mButtonImage = null; private TextView mButtonText = null; public MyPhoneImageButton (Context context): base (context) {mButtonImage = new ImageView (context ); mButtonText = new TextView (context); mButtonImage. setPadding (0, 0, 0, 0); mButtonText. setPadding (0, 0, 0, 0); // set the attribute Clickable = true for the current layout; Focusable = true; AddView (mButtonText); AddView (mButtonImage );} public void setImageResource (int resId) {mButtonImage. setImageResource (resId);} public void setText (string resId) {mButtonText. text = resId;} public void setTextColor (int color) {mButtonText. setTextColor (Resources. getColor (color ));}}View Code

Then write the xml layout for the Custom Button in the main layout. Note that our "Button" is actually a linear layout. Therefore, LinearLayout should be written in xml instead of Button or ImageButton.

 

<LinearLayout android: layout_width = "wrap_content" android: layout_height = "wrap_content" android: id = "@ + id/tvPPhone" android: orientation = "horizontal"/>View Code

 

Finally, set the listener for the Custom button in the Activity.

 

Private LinearLayout llbtDataConfig = null; // private MyPhoneImageButton btDataConfig = null; btDataConfig = new MyPhoneImageButton (this); btDataConfig. setTextColor (Resource. color. text_color_projectInfo); btDataConfig. setText ("I Am a text"); btDataConfig. setImageResource (Resource. drawable. phone); llbtDataConfig = FindViewById <LinearLayout> (Resource. id. tvPPhone); llbtDataConfig. addView (btDataConfig); llbtDataConfig. setOnClickListener (new llbtDataConfig_Click (); // listener events inherit from public class llbtDataConfig_Click: Java. lang. object, View. IOnClickListener {public void OnClick (View v ){}}View Code

 

In addition, it is better to monitor click events.

            llbtDataConfig.Click += (object sender, EventArgs e) => {                llbtDataConfig_Click ();            };

 

 

 

 


Custom messagebox C # How to implement a custom MessageBox, buttons, images, and information can be customized, with source code

Passed. Check it out.

The buttons in a webpage written in html are cool. How can I replace a button image with a custom image?

<Input type = image src = "image path"/> This is only a submission button. If you want to set a button, such as a reset button, you need to combine a piece of JAVASCRIPT. If you do not want to set this button, check it online. it's easy to know.
Of course, you can also make FLASH as the previous one said.
However, making a single button FLASH is not cost-effective.

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.