• [Android学习笔记]EditText的使用


    EditText就是我们最常用的文本输入框

    常用属性见官方文档

    主要是以下几个问题:

    1.取消默认获取焦点

    Activity启动时候会把焦点默认停留在第一个EditText控件上

    一般的解决方法是在此EditeText之前加入一个看不到的控件,让其先于EditText获取焦点

    加入一个看不到LinearLayout控件

            <LinearLayout
            android:focusable="true" 
            android:focusableInTouchMode="true"
            android:layout_width="0px" 
            android:layout_height="0px"/>
    LinearLayout

    2.修改EditeText样式

    一般步骤为:

    a).res/drawable文件夹下建立editeText需要的外观样式

    b).定义selector,引用样式

    默认样式bg_edittext_normal.xml

    <?xml version="1.0" encoding="UTF-8"?>   
    <shape xmlns:android="http://schemas.android.com/apk/res/android">   
        <solid android:color="#FFFFFF" />   
        <corners android:radius="3dip"/>  
        <stroke    
            android:width="1dip"    
            android:color="#cccccc" />   
    </shape>
    bg_edittext_normal.xml

    获取焦点的样式bg_edittext_focused.xml

    <?xml version="1.0" encoding="UTF-8"?>   
    <shape xmlns:android="http://schemas.android.com/apk/res/android">   
        <solid android:color="#FFFFFF" />   
        <corners android:radius="3dip"/>  
        <stroke    
            android:width="1dip"    
            android:color="#728ea3" />   
    </shape>
    bg_edittext_focused.xml

    selector:bg_edittext.xml

    <?xml version="1.0" encoding="UTF-8"?>   
    <selector xmlns:android="http://schemas.android.com/apk/res/android">  
            <item android:state_window_focused="false" android:drawable="@drawable/bg_edittext_normal" />  
            <item android:state_focused="true" android:drawable="@drawable/bg_edittext_focused" />  
    </selector>
    bg_edittext.xml

    使用selector:

            <EditText
                android:id="@+id/editTextContent"
                android:layout_width="350dp"
                android:layout_height="match_parent"
                android:background="@drawable/bg_edittext"
                android:text="123" />
    使用EditText
    人生就是一局不能Again的DOTA
  • 相关阅读:
    利用Python进行数据分析笔记-时间序列(时区、周期、频率)
    形象易懂讲解算法I——小波变换
    小波变换与傅里叶变换的区别
    Thinkpad E550 开启 Legacy Only
    Thinkpad E550 开启 虚拟化
    常见音频接口
    IAR embedded Workbench for ARM 8.32.1 安装包
    stm32f767 无操作系统 LwIP 移植 (一)
    stm32f767 无操作系统 LwIP 移植 (二)
    北京市电力公司
  • 原文地址:https://www.cnblogs.com/hellenism/p/3655558.html
Copyright © 2020-2023  润新知