Android EditText設(shè)置邊框的操作方法
Android EditText設(shè)置邊框
簡介
Android應(yīng)用程序中給EditText設(shè)置邊框。
效果圖:

快速開始
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="賬號(hào):"
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="請輸入賬號(hào)"
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>到此這篇關(guān)于Android EditText設(shè)置邊框的文章就介紹到這了,更多相關(guān)Android EditText邊框內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Android?SeekBar充當(dāng)Progress實(shí)現(xiàn)兔兔進(jìn)度條Plus
這篇文章主要為大家介紹了Android?SeekBar充當(dāng)Progress實(shí)現(xiàn)兔兔進(jìn)度條Plus示例,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
Android App中使用AudioManager類來編寫音頻播放器
這篇文章主要介紹了Android App中使用AudioManager類來編寫音樂播放器的方法,文中舉了一個(gè)簡單的例子實(shí)現(xiàn)了基礎(chǔ)的播放暫停和靜音等功能,需要的朋友可以參考下2016-04-04
Android 高德地圖之poi搜索功能的實(shí)現(xiàn)代碼
這篇文章主要介紹了android 高德地圖之poi搜索功能的實(shí)現(xiàn)代碼,在實(shí)現(xiàn)此功能時(shí)遇到很多問題,在文章都給大家提到,需要的朋友可以參考下2017-08-08
Android自定義水平進(jìn)度條的圓角進(jìn)度
這篇文章主要為大家詳細(xì)介紹了Android自定義水平進(jìn)度條的圓角進(jìn)度,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08
Jenkins打包android應(yīng)用時(shí)自動(dòng)簽名apk詳解
這篇文章主要介紹了Jenkins打包android應(yīng)用時(shí)自動(dòng)簽名apk詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2019-07-07
Android實(shí)現(xiàn)通過手勢控制圖片大小縮放的方法
這篇文章主要介紹了Android實(shí)現(xiàn)通過手勢控制圖片大小縮放的方法,結(jié)合實(shí)例形式分析了Android控制圖片縮放的原理、實(shí)現(xiàn)步驟與相關(guān)操作技巧,需要的朋友可以參考下2016-10-10
Android?Flutter實(shí)現(xiàn)搜索的三種方式詳解
這篇文章主要為大家詳細(xì)介紹了Android?Flutter實(shí)現(xiàn)搜索的三種方式,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,感興趣的可以了解一下2022-08-08
Flutter開發(fā)之路由與導(dǎo)航的實(shí)現(xiàn)
這篇文章主要介紹了Flutter開發(fā)之路由與導(dǎo)航的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12

