Skip to content

Instantly share code, notes, and snippets.

@hanji1122
Last active August 29, 2015 13:57
Show Gist options
  • Save hanji1122/9526212 to your computer and use it in GitHub Desktop.
Save hanji1122/9526212 to your computer and use it in GitHub Desktop.
通过内置账户自动补全邮箱注册,参见https://plus.google.com/+AndroidDevelopers/posts/DgLSWqZ7eVj
public class Register extends Activity {
private AutoCompleteTextView mEmailAutoTV;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.layout_register);
mEmailAutoTV = (AutoCompleteTextView) this.findViewById(R.id.atv_sign);
final Account[] accounts = AccountManager.get(this).getAccounts();
final Set<String> emailSet = new HashSet<String>();
for (Account account : accounts) {
if (Patterns.EMAIL_ADDRESS.matcher(account.name).matches()) {
emailSet.add(account.name);
}
}
List<String> emails = new ArrayList<String>(emailSet);
mEmailAutoTV.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_dropdown_item_1line, emails));
}
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="Sign Up"
android:textSize="30sp"
android:layout_margin="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<AutoCompleteTextView
android:id="@+id/atv_sign"
android:selectAllOnFocus="true"
android:imeActionLabel="注册"
android:inputType="textEmailAddress"
android:hint="Enter Your Email"
style="@style/TextAppearance.Autocomplete.Suggestion"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment