最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android實(shí)現(xiàn)QQ登錄界面遇到問(wèn)題及解決方法

 更新時(shí)間:2016年09月01日 10:53:05   作者:西門吃雪  
本文給大家介紹android仿qq登錄界面的實(shí)現(xiàn)代碼,在實(shí)現(xiàn)此功能過(guò)程中遇到各種問(wèn)題,但是最終都順利解決,如果大家對(duì)android qq登錄界面實(shí)現(xiàn)方法感興趣的朋友一起學(xué)習(xí)吧

先給大家炫下效果圖:

首先過(guò)程中碰到的幾個(gè)問(wèn)題:

1、對(duì) EditText 進(jìn)行自定義背景

2、運(yùn)行時(shí)自動(dòng) EditText 自動(dòng)獲得焦點(diǎn)

3、在獲得焦點(diǎn)時(shí)即清空 hint ,而不是輸入后清空

4、清空按鈕的出現(xiàn)時(shí)機(jī)(在得到焦點(diǎn)并且有輸入內(nèi)容時(shí))

  .........

--- 這些問(wèn)題都有一一解決 ---

以下是代碼:

布局 fragment_main(問(wèn)題2)

<!-- android:focusable="true" 
  android:focusableInTouchMode="true" 
  把EditText默認(rèn)的行為截?cái)嗔耍?-->
<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="10"
  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="10"
  android:background="@drawable/bg_edittext"
  android:inputType="textPassword"
  android:gravity="center"
  android:textColor="#6A6A6C"
  android:hint="@string/inpwd"
  android:textColorHint="#ECEDDD" >
 </EditText>
 <Button
  android:id="@+id/button1"
  android:layout_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" />
 <LinearLayout
  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:gravity="center"
   android:text="@string/faillogin"
   android:textColor="#0EB1EF" />
  <TextView
   android:id="@+id/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:layout_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 和 EditText 的背景(問(wèn)題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">登錄</string>
 <string name="faillogin">無(wú)法登錄?</string>
 <string name="regist">新用戶注冊(cè)</string>
 <string name="inaccount">QQ號(hào)/手機(jī)號(hào)/郵箱</string>
 <string name="inpwd">密碼</string>
 <string name="sucess">登錄成功</string>
</resources>
strings

MainActivity (問(wèn)題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 button;
private Button clearButton1;
private Button clearButton2;
// 得到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);
// 對(duì)EditText進(jìn)行焦點(diǎn)變更監(jiān)聽(tīng)
editText1.setOnFocusChangeListener(new EditTextListener(clearButton1));
editText2.setOnFocusChangeListener(new EditTextListener(clearButton2));
// 對(duì)清空按鈕進(jìn)行點(diǎn)擊監(jiān)聽(tīng)
clearButton1.setOnClickListener(new ClearButtonListener());
clearButton2.setOnClickListener(new ClearButtonListener());
// 對(duì)EditText進(jìn)行編輯監(jiān)聽(tīng)
editText1.addTextChangedListener(new MyEditTextWatcher(editText1));
editText2.addTextChangedListener(new MyEditTextWatcher(editText2));
}
/**
* 對(duì)EditText的內(nèi)容進(jìn)行實(shí)時(shí)監(jiān)控
* 
* @author Auser
* 
*/
class MyEditTextWatcher implements TextWatcher {
private CharSequence temp;
private EditText editText;
public MyEditTextWatcher(EditText editText) {
this.editText = editText;
}
@Override
// int start開(kāi)始的位置, int count被改變的舊內(nèi)容數(shù), int after改變后的內(nèi)容數(shù)量
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// 這里的s表示改變之前的內(nèi)容,通常start和count組合,可以在s中讀取本次改變字段中被改變的內(nèi)容。而after表示改變后新的內(nèi)容的數(shù)量。
}
@Override
// int start開(kāi)始的位置, int before改變前的內(nèi)容數(shù)量, int count新增量
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// 這里的s表示改變之后的內(nèi)容,通常start和count組合,可以在s中讀取本次改變字段中新的內(nèi)容。而before表示被改變的內(nèi)容的數(shù)量。
temp = s;
}
@Override
// 表示最終內(nèi)容
public void afterTextChanged(Editable s) {
if (temp.length() > 0) {
// 設(shè)置清空按鈕為可見(jiàn)
if (editText == editText1) {
clearButton1.setVisibility(View.VISIBLE);
} else if (editText == editText2) {
clearButton2.setVisibility(View.VISIBLE);
}
} else {
// 設(shè)置清空按鈕不可見(jiàn)
if (editText == editText1) {
clearButton1.setVisibility(View.INVISIBLE);
} else if (editText == editText2) {
clearButton2.setVisibility(View.INVISIBLE);
}
}
}
}
/**
* 清空按鈕點(diǎn)擊事件
* 
* @author
* 
*/
class ClearButtonListener implements OnClickListener {
@Override
public void onClick(View view) {
if (view == clearButton1) {
editText1.setText("");
} else if (view == clearButton2) {
editText2.setText("");
}
}
}
/**
* 焦點(diǎn)變更事件
* 
* @author Auser
* 
*/
class EditTextListener implements OnFocusChangeListener {
private Button clear;
public EditTextListener(Button clear) {
this.clear = clear;
}
@Override
public void onFocusChange(View v, boolean hasFocus) {
EditText textView = (EditText) v;
String hint;
if (hasFocus) {
// 當(dāng)獲取焦點(diǎn)時(shí)如果內(nèi)容不為空則清空按鈕可見(jiàn)
if (!textView.getText().toString().equals("")) {
clear.setVisibility(View.VISIBLE);
}
// if (textView == editText2) {
// // 設(shè)置輸入格式為不可見(jiàn)的密碼格式
// textView.setInputType(InputType.TYPE_CLASS_TEXT
// | InputType.TYPE_TEXT_VARIATION_PASSWORD);
// }
hint = textView.getHint().toString();
// 給TextView添加額外的數(shù)據(jù)
textView.setTag(hint);
textView.setHint("");
} else {
// 當(dāng)失去焦點(diǎn)時(shí)清空按鈕不可見(jiàn)
clear.setVisibility(View.INVISIBLE);
// if (textView == editText2) {
// // 設(shè)置輸入格式為可見(jiàn)的密碼格式
// textView.setInputType(InputType.TYPE_CLASS_TEXT
// | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
// }
// 取出之前添加的額外數(shù)據(jù)
hint = textView.getTag().toString();
textView.setHint(hint);
}
}
}
}

下篇文章給大家介紹Android實(shí)現(xiàn)QQ新用戶注冊(cè)界面遇到問(wèn)題及解決方法,感興趣的朋友可以參考下。

以上所述是小編給大家介紹的Android實(shí)現(xiàn)QQ登錄界面遇到問(wèn)題及解決方法,希望對(duì)大家有所幫助,如果大家有任何疑問(wèn)請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)腳本之家網(wǎng)站的支持!

相關(guān)文章

  • Android?Drawable代碼編寫的新姿勢(shì)分享

    Android?Drawable代碼編寫的新姿勢(shì)分享

    Drawable是什么?按照字面翻譯,就是可繪制的,由于能夠繪制的東西很多,所以這個(gè)類是一個(gè)抽象類,下面這篇文章主要給大家介紹了關(guān)于Android?Drawable代碼編寫的新姿勢(shì),需要的朋友可以參考下
    2022-01-01
  • android實(shí)現(xiàn)上滑屏幕隱藏底部菜單欄的示例

    android實(shí)現(xiàn)上滑屏幕隱藏底部菜單欄的示例

    這篇文章主要介紹了android實(shí)現(xiàn)上滑屏幕隱藏底部菜單欄的示例,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-02-02
  • RecyclerView滑動(dòng)到指定Position的方法

    RecyclerView滑動(dòng)到指定Position的方法

    這篇文章主要為大家詳細(xì)介紹了RecyclerView滑動(dòng)到指定Position的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-04-04
  • Android應(yīng)用啟動(dòng)另外一個(gè)apk應(yīng)用的方法

    Android應(yīng)用啟動(dòng)另外一個(gè)apk應(yīng)用的方法

    這篇文章主要介紹了Android應(yīng)用啟動(dòng)另外一個(gè)apk應(yīng)用的方法,涉及Android基于intent的package調(diào)用與管理技巧,需要的朋友可以參考下
    2016-02-02
  • Android圖片壓縮上傳之基礎(chǔ)篇

    Android圖片壓縮上傳之基礎(chǔ)篇

    這篇文章主要介紹了Android圖片壓縮上傳之基礎(chǔ)篇的相關(guān)內(nèi)容,本文介紹的非常詳解,具有參考借鑒價(jià)值,感興趣的朋友一起看下吧
    2016-05-05
  • 詳解升級(jí)Android Studio3.0時(shí)遇到的幾個(gè)問(wèn)題

    詳解升級(jí)Android Studio3.0時(shí)遇到的幾個(gè)問(wèn)題

    本篇文章主要介紹了升級(jí)Android Studio3.0時(shí)遇到的幾個(gè)問(wèn)題,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2017-10-10
  • android實(shí)現(xiàn)可上下回彈的scrollview

    android實(shí)現(xiàn)可上下回彈的scrollview

    這篇文章主要為大家詳細(xì)介紹了android實(shí)現(xiàn)可上下回彈的scrollview,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2022-04-04
  • Android實(shí)現(xiàn)圖片加載進(jìn)度提示

    Android實(shí)現(xiàn)圖片加載進(jìn)度提示

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)圖片加載進(jìn)度提示,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-06-06
  • Android自定義Dialog實(shí)現(xiàn)加載對(duì)話框效果

    Android自定義Dialog實(shí)現(xiàn)加載對(duì)話框效果

    這篇文章將介紹如何定制當(dāng)今主流的對(duì)話框,通過(guò)自定義dialog實(shí)現(xiàn)加載對(duì)話框效果,具體實(shí)現(xiàn)代碼大家通過(guò)本文學(xué)習(xí)吧
    2018-05-05
  • Android觸摸事件傳遞機(jī)制

    Android觸摸事件傳遞機(jī)制

    這篇文章主要介紹了Android觸摸事件傳遞機(jī)制,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-04-04

最新評(píng)論

石屏县| 革吉县| 兴城市| 噶尔县| 木里| 嵊泗县| 准格尔旗| 兴山县| 河间市| 聂荣县| 扶余县| 犍为县| 措美县| 景东| 婺源县| 浪卡子县| 南部县| 田林县| 永定县| 老河口市| 察隅县| 加查县| 海丰县| 广州市| 柞水县| 井冈山市| 博爱县| 远安县| 西平县| 余干县| 石家庄市| 奈曼旗| 堆龙德庆县| 安陆市| 新营市| 息烽县| 彭阳县| 卫辉市| 宣汉县| 格尔木市| 安徽省|