国产成人精品久久免费动漫-国产成人精品天堂-国产成人精品区在线观看-国产成人精品日本-a级毛片无码免费真人-a级毛片毛片免费观看久潮喷

您的位置:首頁(yè)技術(shù)文章
文章詳情頁(yè)

Android Studio實(shí)現(xiàn)簡(jiǎn)單的QQ登錄界面的示例代碼

瀏覽:122日期:2022-06-06 17:33:29

一、項(xiàng)目概述

QQ是我們?nèi)粘I钍褂米疃嗟能浖唬卿浗缑婧瓦M(jìn)入后的聊天界面、好友列表界面和空間動(dòng)態(tài)界面等。登錄界面的制作比較簡(jiǎn)單,主要考驗(yàn)布局的使用,是實(shí)現(xiàn)QQ項(xiàng)目的第一步。現(xiàn)在APP開(kāi)發(fā)的首要工作都是實(shí)現(xiàn)登錄頁(yè)面,所以學(xué)會(huì)了QQ登錄界面對(duì)以后的軟件開(kāi)發(fā)有著很重要的作用。

二、開(kāi)發(fā)環(huán)境

Android Studio實(shí)現(xiàn)簡(jiǎn)單的QQ登錄界面的示例代碼

三、詳細(xì)設(shè)計(jì)

1、頭像設(shè)計(jì)

首先在layout文件里面選擇了RelativeLayout(相對(duì)布局)作為整個(gè)頁(yè)面的布局。

在頂端放置了一個(gè)ImageView控件,寬度和高度設(shè)置的都是70dp,水平居中設(shè)置為true。

然后使頭像在整個(gè)頁(yè)面下調(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、賬號(hào)輸入框

利用LinearLayout(線性布局)作為賬號(hào)輸入框的外層布局,orientation設(shè)置的為水平排列。

放置了一個(gè)TextView控件,寬度和高度設(shè)置的wrap_content,即適應(yīng)內(nèi)容大小,顯示文本“賬號(hào)”。

緊接著放置一個(gè)EditText控件,用于輸入賬號(hào)內(nèi)容,使用layout_toRightOf屬性定位于賬號(hào)的右側(cè)。

<LinearLayout android: 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: android:layout_width='wrap_content' android:layout_height='wrap_content' android:padding='10dp' android:text='賬號(hào):' android:textColor='#000' android:textSize='20sp' /> <EditText android: 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(線性布局),整體放置在上一個(gè)LinearLayout的下面,控件排列依然為horizontal(水平)。

放置一個(gè)TextView文本顯示框,文本內(nèi)容是“密碼”,文本顏色為黑色,文本大小為20sp。

再放置一個(gè)EditText文本輸入框,inputType設(shè)置為textPassword,輸入時(shí)候會(huì)隱藏輸入內(nèi)容,使用*** 代替。

<LinearLayout android: 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: android:layout_width='wrap_content' android:layout_height='wrap_content' android:padding='10dp' android:text='密碼:' android:textColor='#000' android:textSize='20sp' /> <EditText android: 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、登錄按鈕

在賬號(hào)密碼框下方放置一個(gè)Button控件,文本內(nèi)容為“登錄”,文本顏色為藍(lán)色。

<Button android: 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這個(gè)變量,并與剛剛設(shè)置的登錄按鈕進(jìn)行綁定。

然后使用了setOnClickListener按鈕點(diǎn)擊事件監(jiān)聽(tīng)器,在監(jiān)聽(tīng)器里面聲明了onClick方法,在里面聲明了dialog變量,即顯示對(duì)話框。

setTitle( )設(shè)置了對(duì)話框的標(biāo)題為“賬號(hào)或密碼不能為空”,setIcon( )設(shè)置了對(duì)話框標(biāo)題圖標(biāo),setMessage( )設(shè)置對(duì)話框的提示信息為'請(qǐng)輸入賬號(hào)和密碼' 。

最后添加了'確定'按鈕和“取消”按鈕,點(diǎn)擊按鈕都會(huì)調(diào)用dialog.dismiss()方法關(guān)閉對(duì)話框。

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('賬號(hào)或密碼不能為空') //設(shè)置對(duì)話框的標(biāo)題 .setIcon(R.mipmap.ic_launcher)//設(shè)置對(duì)話框標(biāo)題圖標(biāo) .setMessage('請(qǐng)輸入賬號(hào)和密碼')//設(shè)置對(duì)話框的提示信息 //添加'確定'按鈕 .setPositiveButton('確定', new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) {dialog.dismiss(); //關(guān)閉對(duì)話框MainActivity.this.finish(); //關(guān)閉MainActivity } }) //添加“取消”按鈕 .setNegativeButton('取消', new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) {dialog.dismiss(); //關(guān)閉對(duì)話框 } });dialog = builder.create();dialog.show(); } }); }}

四、項(xiàng)目效果

1、用模擬器運(yùn)行。

Android Studio實(shí)現(xiàn)簡(jiǎn)單的QQ登錄界面的示例代碼

2、輸入賬號(hào)不輸入密碼,點(diǎn)擊登錄按鈕會(huì)顯示提醒對(duì)話框。

Android Studio實(shí)現(xiàn)簡(jiǎn)單的QQ登錄界面的示例代碼

3、輸入賬號(hào)和密碼。

Android Studio實(shí)現(xiàn)簡(jiǎn)單的QQ登錄界面的示例代碼

五、項(xiàng)目總結(jié)

本次項(xiàng)目屬于比較基礎(chǔ)的內(nèi)容,希望初學(xué)者通過(guò)這次項(xiàng)目熟練掌握界面布局和控件的使用,為以后的項(xiàng)目開(kāi)發(fā)打下堅(jiān)實(shí)的基礎(chǔ)。

本次項(xiàng)目文件的源碼鏈接如下:QQ_jb51.rar

到此這篇關(guān)于Android Studio實(shí)現(xiàn)簡(jiǎn)單的QQ登錄界面的示例代碼的文章就介紹到這了,更多相關(guān)Android Studio QQ登錄界面內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: qq
相關(guān)文章:
主站蜘蛛池模板: 深夜福利成人 | 黄色三级网站在线观看 | 日韩精品一区二区三区 在线观看 | 亚洲成a v人片在线观看 | 国产成人免费片在线视频观看 | 国产日韩欧美精品一区 | 欧美精品hdvdeosex4k | 香港激情黄三级在线视频 | 久久在线资源 | 欧美一区=区三区 | 在线免费观看成年人视频 | 欧美黑人性xxx猛交 欧美很黄视频在线观看 | 国产一级片免费 | 国产一区二区三区亚洲综合 | 免费观看国产网址你懂的 | 亚洲成a人片在线观 | 免费乱人伦| 99久久精品无码一区二区毛片 | 午夜宅男在线永远免费观看网 | 亚洲欧美高清视频 | 国产免费怡红院视频 | 手机看片av| 国产精品自拍在线观看 | 国产视频二 | 国产一级一片免费播放 | 特级毛片免费视频播放 | 牛牛a级毛片在线播放 | 久草网在线视频 | 台湾三级 | 日本aaaa片毛片免费观看 | 亚洲波多野结衣日韩在线 | 欧美日韩亚洲第一页 | 久久精品免费一区二区视 | 国产色司机在线视频免费观看 | 337p欧美| 久久精品国产精品青草不卡 | 国产愉拍精品手机 | 久久久青青久久国产精品 | 成年女人免费毛片视频永久 | 亚洲国产一区二区三区四区五区 | 一级视频免费观看 |