Android QQ Login interface encountered problems and solutions _android

Source: Internet
Author: User

Let's show you the effect chart:

The first of several problems encountered in the process:

1, the edittext to customize the background

2, the runtime automatic edittext automatically get focus

3, when the focus is to clear the hint, rather than empty after the input

4, the opportunity to empty the button (when the focus and have input content)

.........

---these problems are solved in one by one---

Here's the code:

Layout Fragment_main (Issue 2)

<!--android:focusable= "true" android:focusableintouchmode= "true" truncates edittext default behavior! --> <relativelayout xmlns:android= "http://schemas.android.com/apk/res/android" xmlns:tools= "http://" Schemas.android.com/tools "android:layout_width=" match_parent "android:layout_height=" Match_parent "Android: Background= "#ECEDF1" android:focusable= "true" android:focusableintouchmode= "true" tools:context= "
  Com.dragon.android.qqlogin.mainactivity$placeholderfragment "> <imageview android:id=" @+id/imageView1 " Android:layout_width= "70DP" android:layout_height= "70DP" android:layout_centerhorizontal= "true" Android:layout_ Marginbottom= "5DP" android:layout_margintop= "40DP" android:src= "@drawable/A"/> <edittext android:id= "@+id/ EditText1 "android:layout_width=" match_parent "android:layout_height=" wrap_content "android:layout_below=" @id ImageView1 "android:ems=" android:background= "@drawable/bg_edittext" android:inputtype= "Textpersonname" Android:gravity= "center" android:textcolor= "#6A6A6C" android:hint= "@string/inaccount" android:textcolorhint= "#ECEDDD" > </EditText> <edittext android:id= "@+id/edittext2" android:layout_width= "Match_parent" android:layout _height= "Wrap_content" android:layout_below= "@id/edittext1" android:ems= "" android:background= "@drawable/bg_ EditText "android:inputtype=" Textpassword "android:gravity=" center "android:textcolor=" #6A6A6C "android:hint=" @str Ing/inpwd "android:textcolorhint=" #ECEDDD > </EditText> <button android:id= "@+id/button1" Android:lay Out_width= "Match_parent" android:layout_height= "40DP" android:layout_below= "@id/edittext2" Android:layout_ marginleft= "20DP" android:layout_marginright= "20DP" android:layout_margintop= "10DP" android:background= "@drawable /bg_button "android:text=" @string/button "android:gravity= Center" android:textcolor= "#F9FAFB"/> <linearlayo UT android:layout_width= "Match_parent" android:layout_height= "Wrap_content" android:layout_alignparentbottom= "true" android:padding= "10DP" > <TextView Android:id= "@+id/textview2" android:layout_width= "wrap_content" android:layout_height= "Wrap_content" android:g ravity= "center" android:text= "@string/faillogin" android:textcolor= "#0EB1EF/> <textview" android:id=
   D/TEXTVIEW3 "android:layout_width=" "Match_parent" android:layout_height= "wrap_content" android:gravity= "right" android:text= "@string/regist" android:textcolor= "#0EB1EF"/> </LinearLayout> <button android:id= "@+id/ Button2 "android:layout_width=" 16DP "android:layout_height=" 16DP "android:layout_aligntop=" @id/edittext1 "Android: layout_margintop= "15DP" android:layout_alignparentright= "true" android:layout_marginright= "10DP" Android: background= "@drawable/clear" android:visibility= "invisible"/> <button android:id= "@+id/button3" Android:layo Ut_width= "16DP" Android:layout_height= "16DP" android:layout_aligntop= "@id/edittext2" android:layout_margintop= "15DP" android:layout_alignleft= "@+id
/button2 "android:background=" @drawable/clear "android:visibility=" invisible "/> </RelativeLayout> Fragment_main

Button and EditText background (issue 1)

<?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
 <stroke android:width=" 1px "android:color=" #00ACED "/>
 <solid android:color=" #00ACED "/>
 <corners android:radius=" 10DP "/>
</shape>
Bg_button
<?xml version= "1.0" encoding= "Utf-8"?> <shape xmlns:android=
"http://schemas.android.com/apk/res/" Android ">
 <stroke android:width=" 1px "android:color=" #ECEDF1 "/>
 <solid android:color=" # F9FAFB "/>
 <corners android:radius=" 10DP "/> <padding android:top= 
  " 10DP " 
  android: bottom= "10DP"/>
</shape>
bg_edittext
<?xml version= "1.0" encoding= "Utf-8"?>
<resources>
 <string name= "App_name" >qqloginnew </string>
 <string name= "action_settings" >Settings</string>
 <string name= "button" > Login </string>
 <string name= "Faillogin" > Unable to login?</string>
 <string name= "Regist" > New user Registration </string>
 <string name= "Inaccount" >QQ number/Mobile number/mailbox </string>
 <string name= "Inpwd" > Password </string>
 <string name= "sucess" > Login success </string>
</resources>
strings

Mainactivity (question 3, 4 ...)

Package com.dragon.android.qqloginnew;
Import android.app.Activity;
Import Android.os.Bundle;
Import android.text.Editable;
Import Android.text.TextWatcher;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.view.View.OnFocusChangeListener;
Import Android.widget.Button;
Import Android.widget.EditText; public class Mainactivity extends activity {private edittext editText1; private edittext editText2;//Private Button but
ton
Private Button ClearButton1;
Private Button ClearButton2;
Gets the attribute in strings//private String string2 = Getresources (). getString (R.string.inaccount); @Override protected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview (
R.layout.fragment_main);
EditText1 = (edittext) Findviewbyid (R.ID.EDITTEXT1);
EditText2 = (edittext) Findviewbyid (R.ID.EDITTEXT2);
Button = (button) Findviewbyid (R.id.button1);
ClearButton1 = (Button) Findviewbyid (R.id.button2); ClearButton2 = (Button) Findviewbyid (r.id.BUTTON3);
Focus change Monitoring for EditText Edittext1.setonfocuschangelistener (new Edittextlistener (ClearButton1));
Edittext2.setonfocuschangelistener (New Edittextlistener (ClearButton2));
Click on the empty button to listen for Clearbutton1.setonclicklistener (New Clearbuttonlistener ());
Clearbutton2.setonclicklistener (New Clearbuttonlistener ());
Edit and monitor the EditText Edittext1.addtextchangedlistener (new Myedittextwatcher (EDITTEXT1));
Edittext2.addtextchangedlistener (New Myedittextwatcher (EDITTEXT2)); /** * EditText content for real-time monitoring * * @author auser * * * */class Myedittextwatcher implements Textwatcher {private charsequence
Temp
Private EditText EditText; Public Myedittextwatcher (EditText edittext) {this.edittext = EditText;} @Override//int start position, the number of old content changed by int count, The amount of content after the int after changed public void Beforetextchanged (charsequence s, int start, int count, int after) {//Here's s represents change before content, usually star A combination of T and count to read the changed contents of this changed field in S.
After that, the number of new content after the change. @Override//int start position, the amount of content before int before changed, int count new increment public void OntextchaNged (charsequence s, int start, int before, int count) {///Here's s represents the changed content, usually the start and count combinations that can be read in s to the new content in this changed field.
And before represents the amount of content that is changed.
temp = s; @Override//represents final content public void aftertextchanged (Editable s) {if (temp.length () > 0) {//Set empty button to visible if (EditText = = EDITTEXT1) {clearbutton1.setvisibility (view.visible);} else if (EditText = = editText2) {clearbutton2.setvisibility (
view.visible); } else {//Set the empty button is not visible if (EditText = editText1) {clearbutton1.setvisibility (view.invisible);} else if (EditText = ed
ITTEXT2) {clearbutton2.setvisibility (view.invisible);}} }/** * Empty button click event * * @author * * */class Clearbuttonlistener implements Onclicklistener {@Override public void OnClick (View view) {if (view = = ClearButton1) {edittext1.settext ("");}
else if (view = = ClearButton2) {edittext2.settext ("");}}} /** * Focus Change Event * * @author auser * */class Edittextlistener implements Onfocuschangelistener {private Button clear; publ IC Edittextlistener (Button clear) {this.clear = CLEAr
@Override public void Onfocuschange (View V, boolean hasfocus) {edittext TextView = (edittext) v;
String hint; if (hasfocus) {//When the focus is not empty, the empty button is visible if (!textview.gettext (). toString (). Equals ("")) {clear.setvisibility (
view.visible); }//if (TextView = = editText2) {////Set input format as invisible password format//Textview.setinputtype (Inputtype.type_class_text//|
Inputtype.type_text_variation_password);
} hint = Textview.gethint (). toString ();
Add additional data to the TextView textview.settag (hint); Textview.sethint ("");} else {///The empty button is not visible when the focus is lost clear.setvisibility (view.invisible);//if (TextView = = editText2) {////Set input format as visible password format//TEXTV Iew.setinputtype (Inputtype.type_class_text//|
Inputtype.type_text_variation_visible_password);
///Remove additional data added before hint = Textview.gettag (). toString ();
Textview.sethint (hint); }
}
}
}

The next article to introduce Android QQ new user registration interface encountered problems and solutions, interested friends can refer to.

The above is a small set to introduce the Android QQ login interface problems and solutions, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

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.