Android EditText設置邊框的操作方法
Android EditText設置邊框
簡介
Android應用程序中給EditText設置邊框。
效果圖:
快速開始
1.在res/drawable目錄下新建樣式文件 edit_background.xml。
<?xml version="1.0" encoding="utf-8"?> <layer-list xmlns:android="http://schemas.android.com/apk/res/android"> <item> <shape android:shape="rectangle"> <solid android:color="#efefef"/> <corners android:radius="5dp"/> <stroke android:width="1dp" android:color="#505050"/> </shape> </item>
2.布局文件中使用邊框效果,/res/layout/activity_edit_text.xml。
android:background=“@drawable/edit_background”
<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context=".EditTextActivity"> <TextView android:id="@+id/name_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="賬號:" android:textSize="18sp" android:textColor="#353535" android:layout_marginTop="60dp" android:layout_marginStart="60dp" app:layout_constraintTop_toTopOf="parent" app:layout_constraintLeft_toLeftOf="parent"/> <EditText android:id="@+id/edit_name" android:layout_width="200dp" android:layout_height="40dp" android:hint="請輸入賬號" android:gravity="center" android:inputType="number" android:background="@drawable/edit_background" android:layout_marginStart="10dp" app:layout_constraintTop_toTopOf="@id/name_label" app:layout_constraintBottom_toBottomOf="@id/name_label" app:layout_constraintLeft_toRightOf="@id/name_label"/> <TextView android:id="@+id/pwd_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="密碼:" android:textSize="18sp" android:textColor="#353535" android:layout_marginTop="40dp" android:layout_marginStart="60dp" app:layout_constraintTop_toBottomOf="@id/name_label" app:layout_constraintLeft_toLeftOf="parent"/> <EditText android:id="@+id/edit_pwd" android:layout_width="200dp" android:layout_height="40dp" android:hint="請輸入密碼" android:gravity="center" android:inputType="textPassword" android:background="@drawable/edit_background" android:layout_marginStart="10dp" app:layout_constraintTop_toTopOf="@id/pwd_label" app:layout_constraintBottom_toBottomOf="@id/pwd_label" app:layout_constraintLeft_toRightOf="@id/pwd_label"/> <Button android:id="@+id/btn_login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="ok" android:layout_marginTop="30dp" android:layout_marginStart="110dp" app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintTop_toBottomOf="@id/pwd_label"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Cancel" android:layout_marginStart="50dp" app:layout_constraintTop_toTopOf="@id/btn_login" app:layout_constraintLeft_toRightOf="@id/btn_login"/> </android.support.constraint.ConstraintLayout>
到此這篇關于Android EditText設置邊框的文章就介紹到這了,更多相關Android EditText邊框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
Flutter 枚舉值enum和int互相轉(zhuǎn)化總結
這篇文章主要為大家介紹了Flutter 枚舉值enum和int互相轉(zhuǎn)化總結分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-02-02Android仿淘寶詳情頁面viewPager滑動到最后一張圖片跳轉(zhuǎn)的功能
需要做一個仿淘寶客戶端ViewPager滑動到最后一頁,再拖動的時候跳到詳情的功能,剛開始我也迷糊了,通過查閱相關資料發(fā)現(xiàn)有好多種實現(xiàn)方法,下面小編給大家分享實例代碼,感興趣的朋友一起看看吧2017-03-03Android中應用前后臺切換監(jiān)聽的實現(xiàn)詳解
這篇文章主要給大家介紹了關于Android中應用前后臺切換監(jiān)聽實現(xiàn)的相關資料,文中通過示例代碼介紹的非常詳細,對大家具有一定的參考學習價值,需要的朋友們下面跟著小編來一起學習學習吧。2017-07-07Android App使用RecyclerView實現(xiàn)上拉和下拉刷新的方法
RecyclerView一經(jīng)推出便被認為是替代ListView的存在,那么ListView的上拉和下拉刷新我們同樣可以使用RecyclerView來做到,這里我們就來看一下Android App使用RecyclerView實現(xiàn)上拉和下拉刷新的方法,首先先來點RecyclerView的小介紹:2016-06-06ubuntu下 AndroidStudio4.1啟動報錯問題的解決
這篇文章主要介紹了ubuntu下 AndroidStudio4.1啟動報錯問題的解決,本文給大家分享個人經(jīng)驗對大家的學習或工作具有一定的參考借鑒價值,需要的朋友可以參考下2020-10-10Android實現(xiàn)讀寫USB串口數(shù)據(jù)
這篇文章主要為大家詳細介紹了Android實現(xiàn)讀寫USB串口數(shù)據(jù),文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2022-09-09