Android介面圓角輸入框實現

2021-06-18 21:11:14 字數 937 閱讀 9922

最終效果如上圖。

main.xml:

<?xml version="1.0" encoding="utf-8"?>

從上面布局檔案可以看到,用到了rounded_outer 和 rounded_text 這兩個xml檔案。

rounded_outer.xml:

<?xml version="1.0" encoding="utf-8"?>  

rounded_text.xml:

<?xml version="1.0" encoding="utf-8"?>  

rounded_outer.xml 使整個布局為圓角的,當然它還有描邊、填充色等屬性設定。

rounded_text.xml 使圓角裡面的文字框為圓角,與rounded_outer.xml的圓角匹配,在這兩個xml檔案中都設定圓角為5dp。

如果不用rounded_text.xml檔案的話,效果如下:

明顯看出「密碼」框顯示的問題。

在main.xml布局**中有如下view:

android:layout_height="1dp"        

android:background="@color/light_grey" />

它是用來分隔上下兩個文字框的,若不加上這段**,兩個文字框之間就不會有一條連線的橫線。

實現上述檢視,用到的就是shape《形狀控制》的使用,參看:android shape的使用。裡面對於各屬性介紹的很詳細。

Android 之 Shape 圓角輸入框

本文主要介紹通過 shape 來設定 edittext 的圓角。shape life search.xml放在 res drawable 資料夾內 在 activity main.xml 主布局中如此使用 head left.png head right.png search left.png pa...

Android 輸入框控制項EditText

android selectallonfocus true 選擇所有對焦點 android inputtype numberpassword 只能接收數字密碼 android inputtype number 數值輸入框 android inputtype date 日期輸入框 android in...

react input輸入框可輸入的最好實現方式

使用的是refs。react中輸入框不能直接定義value。輸入框是可變的,react會提示報錯。需要使用的inchange事件 輸入框內容被改變時觸發 要定義輸入框初始值,需要在componentdidmount中定義,不能在componentwillmount中定義,因為render之後才能取到...