PackageCom.example.xiaolan01;ImportAndroid.graphics.Color;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportAndroid.widget.TextView; Public classMainactivityextendsappcompatactivity {TextView tex1,tex2;//defines two names, which point to the TextView control;Button Bt1,bt2;//define two names, a control that points to a button Charb; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate); Setcontentview (R.layout.activity_main); Tex1= (TextView) Findviewbyid (R.id.textview);//bind the Tex1 and ID textview text together;Tex2 = (TextView) Findviewbyid (R.ID.TEXTVIEW2);//bind the Tex2 and ID textview2 text together;BT1 = (Button) Findviewbyid (R.id.button);//bind the BT1 with the text with the ID button;BT2 = (Button) Findviewbyid (R.id.button2);//bind the BT2 and ID button2 text together;Tex1.settext ("Text 1");//change the text of the control that Tex1 points to,Tex1.settextcolor (Color.green);//change the color that tex1 points to,Tex2.settext ("Text 2");//change the text of the control that Tex2 points to,Tex2.settextcolor (Color.Blue);//change the color that tex2 points to,Bt1.settext ("Key 1");//change the text of the control that bt1 points to,Bt1.settextcolor (Color.cyan);//change the color that bt1 points to,Bt2.settext ("Key 2");//change the text of the control that BT2 points to,Bt2.settextcolor (Color.yellow);//change the color that bt2 points to,Bt1.setonclicklistener (Listener1);//Create a listener for BT1Bt2.setonclicklistener (LISTENER2);//Create a listener for BT2A=0; b=0; } //implementing the Button1 listenerButton.onclicklistener Listener1 =NewButton.onclicklistener () {//Creating Listener Objects Public voidOnClick (View v) {if(a==0) { //What needs to be done in the listener .Tex1.settext ("Key 1 is pressed"); A=1; } Else{Tex1.settext (""); A=0; } } }; //implementing the Button2 listenerButton.onclicklistener Listener2 =NewButton.onclicklistener () {//Creating Listener Objects Public voidOnClick (View v) {if(b==0) { //What needs to be done in the listener .Tex2.settext ("Key 2 has been pressed"); b=1; } Else{Tex2.settext (""); b=0; } } };}
20160706 Key Control text