4-VVI-材料設計之沉浸標題欄和TextInputLayout
零、前言
這是兩個比較小的點,放在一起說一下:
沉浸標題欄:現在基本上都用沉浸標題欄了,不然最頂的一小塊跟app風格不搭
TextInputLayout:包裹一個EditeText,多用於登陸驗證的輸入框
一、沉浸標題欄

沉浸標題欄.png
由於從5.0開始才有,以下會崩掉,所以需要適配處理
values-v19/styles.xml 無效果,僅防止低版本崩掉
<resources> <!--values-v19。v19 開始有 android:windowTranslucentStatus 這個屬性--> <style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowTranslucentStatus">true</item> <item name="android:windowTranslucentNavigation">true</item> </style> </resources>
values-v21/styles.xml
<resources> <!--values-v21 5.0 以上提供了 setStatusBarColor() 方法設定狀態列顏色。--> <style name="TranslucentTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="android:windowTranslucentStatus">false</item> <item name="android:windowTranslucentNavigation">true</item> <!--Android 5.x開始需要把顏色設定透明,否則導航欄會呈現系統預設的淺灰色--> <item name="android:statusBarColor">@android:color/transparent</item> </style> </resources>
使用:給Activity設定主題即可
android:theme="@style/TranslucentTheme"
二、TextInputLayout
依賴
implementation 'com.android.support:design:26.1.0'
輸入框獲得焦點後會有一個上移動畫,還可以設定小眼睛顯隱密碼

TextInputLayout.png
<android.support.design.widget.TextInputLayout android:id="@+id/til2" app:passwordToggleEnabled="true" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/et_pw" android:layout_width="363dp" android:layout_height="wrap_content" android:ems="10" android:hint="登陸密碼" android:inputType="numberPassword" android:textColor="@color/white" android:textColorHint="@color/white" /> </android.support.design.widget.TextInputLayout>
其中 app:passwordToggleEnabled="true"
顯示小眼睛
還有一個點是改變顏色:
可以自己定義一個主題,設定colorAccent的顏色值
<style name="LoginTheme" parent="TranslucentTheme"> <item name="colorAccent">#ffffff</item> </style>
後記、
1.宣告:
[1]本文由張風捷特烈原創,轉載請註明
[2]歡迎廣大程式設計愛好者共同交流
[3]個人能力有限,如有不正之處歡迎大家批評指證,必定虛心改正
[4]你的喜歡與支援將是我最大的動力
2.連線傳送門:
ofollow,noindex">更多安卓技術歡迎訪問:安卓技術棧 我的github地址:歡迎star 張風捷特烈個人網站,程式設計筆記請訪問: http://www.toly1994.com
3.聯絡我
QQ:1981462002
微信:zdl1994328
4.歡迎關注我的微信公眾號,最新精彩文章,及時送達:

公眾號.jpg