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.