4-VVI-材料设计之沉浸标题栏和TextInputLayout

零、前言

这是两个比较小的点,放在一起说一下:
沉浸标题栏:现在基本上都用沉浸标题栏了,不然最顶的一小块跟app风格不搭
TextInputLayout:包裹一个EditeText,多用于登陆验证的输入框

一、沉浸标题栏

9414344-881be0c0fecf31ed.png
沉浸标题栏.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'

输入框获得焦点后会有一个上移动画,还可以设定小眼睛显隐密码

9414344-f642faedc319987a.png
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.连接传送门:

更多安卓技术欢迎访问:安卓技术栈
我的github地址:欢迎star
张风捷特烈个人网站,编程笔记请访问:http://www.toly1994.com

3.联系我

QQ:1981462002
邮箱:1981462002@qq.com
微信:zdl1994328

4.欢迎关注我的微信公众号,最新精彩文章,及时送达:
9414344-c474349cd3bd4b82.jpg
公众号.jpg
原文地址:https://www.cnblogs.com/toly-top/p/9781880.html