----- All the contents of this article come from the user notes on Mu class online, I just sorted it up ----
Button&ImageButton
ImageButton is used to display pictures on the button. So there is no Android: text attribute. And if Android: Text = "I am a button" in the layout file, you will not see any effect in the Android 4.4 environment; Set the background image to fill the entire ImageButton, and set the SRC image to adapt; The text content displayed by Button is recommended to be stored in Strings.xml file
Onclight incident
Three ways to listen to
1. Initialize control; 2. Set the monitor; SetonClickListener 3. Implement the onClick event. a. Anonymous internal class implementation; object .setonClickListener (New Onclicklistener) b. Independent class implementation; object .setonClickListener (listener instance) c. Interface method. Object .setonClickListener (this) 1. Anonymous monitoring event Loginbutton.SetonClickListener (New Onclicklistener () { @Override public void Onclick (view argView0) {{) { // Todo Auto-Generatd Method Stub System.out.println ("My Button was clicked"); } }); 2. Independent incident Loginbutton.setonClickListener (Listener); External separation: Onclicklistener Listener = New Onclicklistener () { @Override public void onClick (view v) { // Todo Auto-Generatd Method Stub System.out.println ("The class to trigger"); } }; 3. Implement interface Public Class MainAICTIVITITY Extends Activity Implements onClickListener { LoginImageButton.SetonClickListener (this); public void onClick (view v) { // Todo Auto-Generatd Method Stub Log.i ("tag", "third method"); } }Implementing the effect of horse race lamps
http://www.imooc.com/video/4308jiyangxiatian1.textView content is too long, default 2. Horse running light effect Method 1: (Only the effect of a single TextView is effective) Android: Singleline = "True" can only be single, the excellent text is displayed as "..." Android: Ellipsize = "Marquee" omission, but there is no horse -raid lamp effect Android: Focusable = "TRUE" Android: FocusableIntouchMode = "TRUE" Method Two: Custom a class inherits TextView, realize the default three constructors, rewrite the ISFOCUSED () method, and return True Change the TextView to (package name+class name) com.imooc.marqueetextViewDemo.marQueetext in the layout file Analysis: Methods Two TextView can achieve the effect of horse -rater lights because the ISFOCUSED () method is rewritten to return True, forcing the TextView to Focused; and Method 1, the first TextView was focused, and the second TextView did not get obtained. Focus, unable to achieve the effect of horse -raising lights question: After rolling for a while, you will stop by yourself: Android: Marqueerepetlimit = "Marquee_forever" Tips: px, dp (dip), SP 1. PX is not recommended in development, PX cannot be used as a reduction according to the resolution; 2.DP and SP can be regarded as equal scaling according to the resolution; 3. Recommend DP when making length limit in the control, SP is more used to display text size; 4. Recommended DP in Android's latest SDKUse AutoCompletetextViewhttp://www.imooc.com/video/1471MISS XuStep: 1. Initialize control: first declare (Private AutoCompletetextView ACTEXTVIEW;), and then initialize (AUTOCOMPLETEXTVIEW) FindViewBy (R.id.autocompletetextView1);); 2. Create an adapter Adapted input content and data source ArrayAdapter <string> adapter = New ArrayAdapter <string> (Content, Resource, Objects); Among them: Content —This, an object of context; Resource —— Android.R.Layout.simple_List_item_1 (XML file similar to Activity_main), a corresponding layout Objects- (parameter Objects is a data source of the string type array) 3. Initialize the data source (the content of the data source is matched the content entered in the text box) Private String [] res), "Data 1", "Data 2", "Data 3", "Data 4 ..."}; Add him and add to adapder ArrayAdapter <string> adapter = New ArrayAdapter <string> (this, Android.Rayout.simple_list_item_1, Res); 4. Bind Adapter with the current AutoCompletetextView control AutoCompletextView.setAdapter (ArrayAdapter); 5. Set a attribute in AutoCompleTetextView to make the input enough 3 characters to start matching Android: Completionthreshold = "3"
MultiAntoCompleteTextView
Use multiautocompletetextViewhttp://www.imooc.com/video/1473idealMultiautocompletetextView is similar to the former Step 1: Initialization control Step 2: Need a adapter Step 3: Initialize the data source Step 4: Bind Adpter with the control Step 5: Set the separator Specific code implementation: ① xml file <multiautocompletetextView Android: ID = "@+ID/mctv" Android: layout_width = "Fill_parent" Android: layout_height = "wrap_content" Android: layout_below = "@+ID/Actv" Android: Completinghint = "1" Android: hint = "Please enter the contact name"/> ② Initialization: Private multiautocompletetextView matv = null; "share", "shieke", "adj", "as", "ad", "sh", "sHADFD", "saf", "dfji"}; ③ Specific operation: /* * Use multiautocompletetextView to implement automatic prompts: * *1. Initialize control, remember FindViewByid (R.id. **) method * 2. Need a adapter * 3. Initialize the data source-> this data source to match the text box content * 4. Bind AdaPter and MultiautocompletetextView, call the setadapter () method * 5. Set a few characters before automatic prompts * 6. Set the separator * */ this.Matv = (multiautocompletextView) findViewByid (R.id.mctv); matv.setadapter (adapter); // Set the comma to the separator, that is, the end symbol matv.settokenizer (New MultiautocompletetextView.comMatokenizer ());Use togglebuttonhttp://www.imooc.com/video/1612Pick from Miss XuTogglebutton default is OFF status Android: texton = "Open" Android: TextOff = "Off" —— Use these two attributes to represent the content displayed in the interface Display the picture through the ImageView control Android: Background = "@Drawable/OFF" to display this picture of OFF Initialize the control in the main activity.xml file 1. State first: Private togglebutton tgbt; Private ImageView Img; 2. Primary initialization TB = (Togglebutton) FindViewByid (R.id.togglebutton1); img = (ImageView) FindViewByid (R.id.imageView1); 3. Surveillance TB switch (setting a monitor for the current TB) Let MainActivityImplements onCheckChanglistener Then set a monitor for TB TB.SetonCheckedChangelistener (this); Method of the listener: Public Void OncheckedChanged The current method is executed when TB is clicked. CompoundButton ButtonView parameter can determine which TB is clicked, buttonView represents the control of the control itself Boolean ischecked parameter is to determine the state of TB, iSchecked represents the state of the control of the control When you click TB, you need to change the picture: Through img.setbackGroundResource (iSchecked? R.Drawable.on: R.Drawable.off);Use RADIOGROUP
http://www.imooc.com/video/1748/0
Do not skip classRADIOGROUP attributes Android: OrTentation = "Horizontal"/"Vertical" RadionButton's default is selected by Android: Check = "TRUE" Add monitoring SetonckedChangelistener (oncheckedChangelistener Listener) to Radiography The coverage method Public Void OncheckedChanged (Radiography Gropupup, Int Checkedid) {{ if (Checkid == R.id.radio0) {// Checkidid is R.ID Log.i ("tag", "You are a boy"); } Else if (Checkdid == R.id.radio1) {{ Log.i ("tag", "You are a girl"); } }