亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

詳解Android Studio實(shí)現(xiàn)用戶(hù)登陸界面demo(xml實(shí)現(xiàn))

瀏覽:2日期:2022-09-24 11:33:11

使用Android Studio 編寫(xiě)的第一個(gè)demo,使用布局文件—xml實(shí)現(xiàn)用戶(hù)登錄界面

注:所建工程均為Android 6.0 所以只要是Android 6.0(包括6.0)以上的真機(jī),模擬機(jī)都可以使用

Step1:Android Studio 開(kāi)發(fā)環(huán)境的搭建:

1.安裝JDK (1.8);2.安裝Android studio (3.3.1) 包含 gradle、sdk manage 、avd manage ;3.使用sdk manage 下載安裝 sdk;4.使用avd manages 創(chuàng)建虛擬機(jī)

Step2: 新建工程項(xiàng)目Myapp2.0

詳解Android Studio實(shí)現(xiàn)用戶(hù)登陸界面demo(xml實(shí)現(xiàn))

詳解Android Studio實(shí)現(xiàn)用戶(hù)登陸界面demo(xml實(shí)現(xiàn))

1.在res/layout/activity_main.xml中編寫(xiě)布局內(nèi)容:

<LinearLayout android:layout_width='match_parent' android:layout_height='match_parent' android:orientation='vertical' android:paddingLeft='55px' android:paddingRight='50px' tools:context='.MainActivity'> <TextView android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:layout_marginStart='@dimen/activity_horizontal_margin' android:layout_marginLeft='@dimen/activity_horizontal_margin' android:layout_marginTop='@dimen/activity_vertical_margin' android:text='Hello Word!' app:layout_constraintLeft_toLeftOf='parent' app:layout_constraintTop_toTopOf='parent' /> <View android:layout_width='match_parent' android:layout_height='2px' android:layout_marginTop='16px' android:background='#000000' /> <TextView android:layout_width='wrap_content' android:layout_height='wrap_content' android:textSize='28dp' android:layout_gravity='center_horizontal' android:layout_marginTop='20px' android:text='登陸界面' /><LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content' android:orientation='horizontal' > <EditText android: android:layout_width='280dp' android:layout_height='wrap_content' android:layout_marginTop='30dp' android:paddingLeft='10dp' android:hint='請(qǐng)輸入賬號(hào)' android:inputType='text'/> <ImageView android: android:layout_width='25dp' android:layout_height='25dp' android:layout_marginTop='37dp' android:src='http://www.aoyou183.cn/bcjs/@drawable/delete' /></LinearLayout> <LinearLayout android:layout_width='match_parent' android:layout_height='wrap_content' android:orientation='horizontal' android:paddingLeft='8px'> <EditText android: android:layout_width='280dp' android:layout_height='wrap_content' android:layout_marginTop='26dp' android:hint='請(qǐng)輸入密碼' android:inputType='textPassword' /> <ImageView android: android:layout_width='25dp' android:layout_height='25dp' android:layout_marginTop='33dp' android:src='http://www.aoyou183.cn/bcjs/@drawable/delete' /></LinearLayout> <Button android: android:layout_width='match_parent' android:layout_height='48dp' android:background='@color/bbutton_danger_disabled_edge' android:layout_marginTop='30dp' android:text='登 陸' android:textSize='30dp' android:textColor='@color/bbutton_danger'/> <Button android: android:layout_width='wrap_content' android:layout_height='wrap_content' android:textSize='15dp' android:layout_gravity='right' android:layout_marginTop='20px' android:background='@color/bbutton_danger' android:text='Adapter' /> </LinearLayout>

2.創(chuàng)建一個(gè)Java class —ExitTextUtils用于封裝清空輸入框的內(nèi)容 :

/** * 用于實(shí)現(xiàn)點(diǎn)擊叉叉時(shí) , 清空輸入框的內(nèi)容 */ class EditTextUtils { public static void clearButtonListener(final EditText et, final View view) { // 取得et中的文字 String etInputString = et.getText().toString(); // 根據(jù)et中是否有文字進(jìn)行X可見(jiàn)或不可見(jiàn)的判斷 if (TextUtils.isEmpty(etInputString)) { view.setVisibility(View.INVISIBLE); } else { view.setVisibility(View.VISIBLE); } //點(diǎn)擊X時(shí)使et中的內(nèi)容為空 view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) {et.setText('');et.requestFocusFromTouch(); } }); //對(duì)et的輸入狀態(tài)進(jìn)行監(jiān)聽(tīng) et.addTextChangedListener(new TextWatcher() { @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void afterTextChanged(Editable s) {if (s.length() == 0) { view.setVisibility(View.INVISIBLE);} else { view.setVisibility(View.VISIBLE);} } }); }}

3.在MainActivity.java 里書(shū)寫(xiě)代碼:

private TextView mTextMessage;@Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); EditText et1 = (EditText) findViewById(R.id.et1); EditText et2 = (EditText) findViewById(R.id.et2); View bt = findViewById(R.id.bt1); View iv = findViewById(R.id.bt2); EditTextUtils.clearButtonListener(et1, bt); EditTextUtils.clearButtonListener(et2, iv); Button btn1 = (Button) findViewById(R.id.bbt1); btn1.setOnClickListener(new View.OnClickListener(){ @Override public void onClick(View v){ //Intent是一種運(yùn)行時(shí)綁定(run-time binding)機(jī)制,它能在程序運(yùn)行過(guò)程中連接兩個(gè)不同的組件,在存放資源代碼的文件夾下下, Intent i = new Intent(MainActivity.this , Main2ActivityAdapterDemo.class); //啟動(dòng) startActivity(i); } }); mTextMessage = (TextView) findViewById(R.id.message); BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation); navigation.setOnNavigationItemSelectedListener(mOnNavigationItemSelectedListener);}

4.布局使用到的資源:

自己建的用于存放自定義的文件 dimens.xml

<resources> <!-- Default screen margins, per the Android Design guidelines. --> <dimen name='activity_horizontal_margin'>16dp</dimen> <dimen name='activity_vertical_margin'>16dp</dimen> <dimen name='text_size_16'>22dp</dimen> <dimen name='space_8'>8</dimen> <dimen name='space_16'>16</dimen> <dimen name='fab_margin'>16dp</dimen></resources>

color.xml

<?xml version='1.0' encoding='utf-8'?><resources> <color name='colorPrimary'>#008577</color> <color name='colorPrimaryDark'>#00574B</color> <color name='colorAccent'>#D81B60</color> <color name='main_gray'>#CCCCCC</color> <color name='main_black'>#000000</color> <color name='bbutton_danger_disabled_edge'>#00CC33</color> <color name='bbutton_danger'>#FFFFFF</color></resources>

截圖

詳解Android Studio實(shí)現(xiàn)用戶(hù)登陸界面demo(xml實(shí)現(xiàn))

詳解Android Studio實(shí)現(xiàn)用戶(hù)登陸界面demo(xml實(shí)現(xiàn))

Step3:運(yùn)行程序。。。截圖如下:

詳解Android Studio實(shí)現(xiàn)用戶(hù)登陸界面demo(xml實(shí)現(xiàn))

下載地址:[LoginDemo.zip]

到此這篇關(guān)于詳解Android Studio實(shí)現(xiàn)用戶(hù)登陸界面demo(xml實(shí)現(xiàn))的文章就介紹到這了,更多相關(guān)Android Studio用戶(hù)登陸內(nèi)容請(qǐng)搜索好吧啦網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持好吧啦網(wǎng)!

標(biāo)簽: Android
相關(guān)文章:
主站蜘蛛池模板: 国产精品素人搭讪在线播放 | 香蕉eeww99国产在线观看 | 香蕉成人啪国产精品视频综合网 | 亚洲日本中文字幕一本 | 国产精品麻豆综合在线 | 日本欧美高清 | 亚洲成人在线播放 | 国产++欧洲韩国野花视频 | 欧洲精品视频在线观看 | 污污的网站免费观看 | 久久香蕉国产线看观看精品蕉 | 999久久免费高清热精品 | 91福利视频免费 | 国产欧美一区二区三区免费看 | 亚洲日韩欧美制服二区dvd | 欧美综合国产精品日韩一 | 欧美一区二区三区不卡免费观看 | 国产情侣露脸 | 一级一片一a一片 | 新婚无套啪啪对白 | 扒开双腿猛进入jk校视频 | 午夜精品视频在线看 | 国产乱子伦一区二区三区 | 国产综合精品日本亚洲777 | 最新黄色网址在线观看 | 91福利在线视频 | 亚洲一区二区三区播放在线 | 国产无套| 中文字幕第13亚洲另类 | 久久er这里都是精品23 | 欧美a级在线观看 | 成年视频在线观看 | 春色影院| 久久福利在线 | 日本特黄特色大片免费视频 | 精品夜夜春夜夜爽久久 | 久久天天躁狠狠躁夜夜爽蜜月 | 午夜影院在线观看视频 | 777在线视频| 亚洲夜色综合久久 | 九九热精品视频在线播放 |