EditText中输入特定的字符,实现校验功能。这个比较简单,就介绍activity_main.xml中的代码和效果图。

一、activity_main.xml中的代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:andro>
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android:digits属性(输入数字)"
        />  
    <EditText 
        
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:digits="0123456789"
        />
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android:digits属性(输入26个小写字母)"
        />  
    <EditText 
        
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:digits="qazwsxedcrfvtgbyhnujmikolp"
        />
    
    
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android:inputType属性(输入数字)"
        />  
    <EditText 
        
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:inputType="number|textCapCharacters"
        />
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android:inputType属性(输入Email)"
        />  
    <EditText 
        
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:inputType="textEmailAddress"
        />
    
    <TextView 
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="android:numeric属性(输入有符号的浮点数)"
        />  
    <EditText 
        
        android:layout_width="200dp"
        android:layout_height="wrap_content"
        android:layout_margin="10dp"
        android:numeric="decimal|signed"
        />
    
</LinearLayout>
View Code

相关文章:

  • 2022-12-23
  • 2021-08-13
  • 2021-12-19
  • 2021-11-08
  • 2022-12-23
  • 2021-07-07
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-09-17
  • 2022-12-23
  • 2022-12-23
  • 2021-05-17
  • 2021-08-05
相关资源
相似解决方案