Android Studio實(shí)現(xiàn)簡單的QQ登錄界面的示例代碼
一、項目概述
QQ是我們?nèi)粘I钍褂米疃嗟能浖?,包含登錄界面和進(jìn)入后的聊天界面、好友列表界面和空間動態(tài)界面等。登錄界面的制作比較簡單,主要考驗(yàn)布局的使用,是實(shí)現(xiàn)QQ項目的第一步?,F(xiàn)在APP開發(fā)的首要工作都是實(shí)現(xiàn)登錄頁面,所以學(xué)會了QQ登錄界面對以后的軟件開發(fā)有著很重要的作用。
二、開發(fā)環(huán)境
三、詳細(xì)設(shè)計
1、頭像設(shè)計
首先在layout文件里面選擇了RelativeLayout(相對布局)作為整個頁面的布局。
在頂端放置了一個ImageView控件,寬度和高度設(shè)置的都是70dp,水平居中設(shè)置為true。
然后使頭像在整個頁面下調(diào)一點(diǎn),不要緊貼著頂端,所以layout_marginTop設(shè)置為40dp。
最后選擇drawable文件夾中的head文件作為頭像。代碼如下:
<ImageView android:id='@+id/iv' android:layout_width="70dp" android:layout_height="70dp" android:layout_centerHorizontal="true" android:layout_marginTop="40dp" android:background="@drawable/head"/>
2、賬號輸入框
利用LinearLayout(線性布局)作為賬號輸入框的外層布局,orientation設(shè)置的為水平排列。
放置了一個TextView控件,寬度和高度設(shè)置的wrap_content,即適應(yīng)內(nèi)容大小,顯示文本“賬號”。
緊接著放置一個EditText控件,用于輸入賬號內(nèi)容,使用layout_toRightOf屬性定位于賬號的右側(cè)。
<LinearLayout android:id="@+id/number_11" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@id/iv" android:layout_centerVertical="true" android:layout_marginBottom="5dp" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:layout_marginTop="15dp" android:background="#ffffff" android:orientation="horizontal"> <TextView android:id="@+id/tv_number" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:text="賬號:" android:textColor="#000" android:textSize="20sp" /> <EditText android:id="@+id/et_number" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_toRightOf="@id/tv_number" android:layout_marginLeft="5dp" android:background="@null" android:inputType="text" android:padding="10dp" /> </LinearLayout>
3、密碼輸入框
最外層依舊是LinearLayout(線性布局),整體放置在上一個LinearLayout的下面,控件排列依然為horizontal(水平)。
放置一個TextView文本顯示框,文本內(nèi)容是“密碼”,文本顏色為黑色,文本大小為20sp。
再放置一個EditText文本輸入框,inputType設(shè)置為textPassword,輸入時候會隱藏輸入內(nèi)容,使用*** 代替。
<LinearLayout android:id="@+id/password_11" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/number_11" android:layout_centerVertical="true" android:layout_marginLeft="10dp" android:layout_marginRight="10dp" android:background="#ffffff" android:orientation="horizontal"> <TextView android:id="@+id/tv_password" android:layout_width="wrap_content" android:layout_height="wrap_content" android:padding="10dp" android:text="密碼:" android:textColor="#000" android:textSize="20sp" /> <EditText android:id="@+id/et_password" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_toRightOf="@id/tv_password" android:background="@null" android:inputType="textPassword" android:padding="10dp"/> </LinearLayout>
4、登錄按鈕
在賬號密碼框下方放置一個Button控件,文本內(nèi)容為“登錄”,文本顏色為藍(lán)色。
<Button android:id="@+id/btn_login" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginTop="38dp" android:background="#3C8DC4" android:text="登錄" android:textColor="#ffffff" android:textSize="20sp" android:layout_below="@+id/password_11" android:layout_alignParentLeft="true" android:layout_alignParentStart="true"/>
5、按鈕點(diǎn)擊事件
在MainActivity里面先聲明了btn這個變量,并與剛剛設(shè)置的登錄按鈕進(jìn)行綁定。
然后使用了setOnClickListener按鈕點(diǎn)擊事件監(jiān)聽器,在監(jiān)聽器里面聲明了onClick方法,在里面聲明了dialog變量,即顯示對話框。
setTitle( )設(shè)置了對話框的標(biāo)題為“賬號或密碼不能為空”,setIcon( )設(shè)置了對話框標(biāo)題圖標(biāo),setMessage( )設(shè)置對話框的提示信息為"請輸入賬號和密碼" 。
最后添加了"確定"按鈕和“取消”按鈕,點(diǎn)擊按鈕都會調(diào)用dialog.dismiss()方法關(guān)閉對話框。
public class MainActivity extends AppCompatActivity { public Button btn; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn = (Button) findViewById(R.id.btn_login);//綁定登錄按鈕 btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { android.app.AlertDialog dialog; android.app.AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this) .setTitle("賬號或密碼不能為空") //設(shè)置對話框的標(biāo)題 .setIcon(R.mipmap.ic_launcher) //設(shè)置對話框標(biāo)題圖標(biāo) .setMessage("請輸入賬號和密碼") //設(shè)置對話框的提示信息 //添加"確定"按鈕 .setPositiveButton("確定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); //關(guān)閉對話框 MainActivity.this.finish(); //關(guān)閉MainActivity } }) //添加“取消”按鈕 .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); //關(guān)閉對話框 } }); dialog = builder.create(); dialog.show(); } }); } }
四、項目效果
1、用模擬器運(yùn)行。
2、輸入賬號不輸入密碼,點(diǎn)擊登錄按鈕會顯示提醒對話框。
3、輸入賬號和密碼。
五、項目總結(jié)
本次項目屬于比較基礎(chǔ)的內(nèi)容,希望初學(xué)者通過這次項目熟練掌握界面布局和控件的使用,為以后的項目開發(fā)打下堅實(shí)的基礎(chǔ)。
本次項目文件的源碼鏈接如下:QQ_jb51.rar
到此這篇關(guān)于Android Studio實(shí)現(xiàn)簡單的QQ登錄界面的示例代碼的文章就介紹到這了,更多相關(guān)Android Studio QQ登錄界面內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android中Service與Activity之間通信的幾種方式
本篇文章主要介紹了Android中Service與Activity之間通信的幾種方式,Activity主要負(fù)責(zé)前臺頁面的展示,Service主要負(fù)責(zé)需要長期運(yùn)行的任務(wù),具有一定的參考價值,有興趣的可以了解一下。2017-02-02Android用注解與反射實(shí)現(xiàn)Butterknife功能
Butterknife是一個在android上實(shí)現(xiàn)ioc(控制反轉(zhuǎn))的一個庫。ioc的核心是解耦。解耦的目的是修改耦合對象時不影響另外一個對象,降低模塊之間的關(guān)聯(lián)。在Spring中ioc更多的是依靠xml的配置。而android上的IOC框架可以不使用xml配置2022-11-11android基礎(chǔ)總結(jié)篇之八:創(chuàng)建及調(diào)用自己的ContentProvider
這篇文章主要介紹了android基礎(chǔ)總結(jié)篇之八:創(chuàng)建及調(diào)用自己的ContentProvider,有興趣的可以了解一下。2016-11-11Android自定義View實(shí)現(xiàn)隨機(jī)驗(yàn)證碼
這篇文章主要介紹了Android自定義View實(shí)現(xiàn)隨機(jī)驗(yàn)證碼的相關(guān)資料,感興趣的小伙伴們可以參考一下2016-07-07Android中ListView Item布局優(yōu)化技巧
這篇文章主要介紹了Android中ListView Item布局優(yōu)化技巧,以實(shí)例形式分析了ListView Item布局的相關(guān)實(shí)現(xiàn)技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-10-10react native中的聊天氣泡及timer封裝成的發(fā)送驗(yàn)證碼倒計時
這篇文章主要介紹了react native中的聊天氣泡及timer封裝成的發(fā)送驗(yàn)證碼倒計時的相關(guān)資料,需要的朋友可以參考下2017-08-08修改Android Studio 的 Logcat 緩沖區(qū)大小操作
這篇文章主要介紹了修改Android Studio 的 Logcat 緩沖區(qū)大小操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-04-04