歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux編程 >> Linux編程

Android自定義密碼鍵盤

先上圖

先看一下鍵盤的布局文件control_digitpasswordkeypad.xml
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <LinearLayout xmlns:Android="http://schemas.android.com/apk/res/android"  
  3.     android:id="@+id/digitkeypadrootlayout"  
  4.     android:layout_width="fill_parent"  
  5.     android:layout_height="fill_parent"  
  6.     android:orientation="vertical" >  
  7.    
  8.     <LinearLayout  
  9.         android:id="@+id/transpwdpdpanel"  
  10.         android:layout_width="fill_parent"  
  11.         android:layout_height="wrap_content"  
  12.         android:layout_weight="1"  
  13.         android:background="#000000" >  
  14.     </LinearLayout>  
  15.    
  16.     <LinearLayout  
  17.         android:layout_width="fill_parent"  
  18.         android:layout_height="wrap_content"  
  19.         android:layout_weight="0"  
  20.         android:background="@drawable/keyboardbackground"  
  21.         android:gravity="bottom"  
  22.         android:orientation="vertical"  
  23.         android:paddingBottom="4dp"  
  24.         android:paddingLeft="4dp"  
  25.         android:paddingRight="4dp" >  
  26.    
  27.         <LinearLayout  
  28.             android:layout_width="fill_parent"  
  29.             android:layout_height="wrap_content"  
  30.             android:layout_marginLeft="4dp"  
  31.             android:layout_marginRight="4dp"  
  32.             android:orientation="horizontal" >  
  33.    
  34.             <EditText  
  35.                 android:id="@+id/digitpadedittext"  
  36.                 android:layout_width="fill_parent"  
  37.                 android:layout_height="wrap_content"  
  38.                 android:gravity="center_vertical|right"  
  39.                 android:singleLine="true" />  
  40.         </LinearLayout>  
  41.    
  42.         <LinearLayout  
  43.             android:layout_width="fill_parent"  
  44.             android:layout_height="wrap_content"  
  45.             android:orientation="horizontal" >  
  46.    
  47.             <Button  
  48.                 android:id="@+id/digitkeypad_1"  
  49.                 android:layout_width="wrap_content"  
  50.                 android:layout_height="46dp"  
  51.                 android:layout_marginLeft="4dp"  
  52.                 android:layout_marginRight="2dp"  
  53.                 android:layout_weight="1"  
  54.                 android:background="@drawable/widget_keypad_digit"  
  55.                 android:gravity="center"  
  56.                 android:text="1"  
  57.                 android:textSize="22sp" >  
  58.             </Button>  
  59.    
  60.             <Button  
  61.                 android:id="@+id/digitkeypad_2"  
  62.                 android:layout_width="wrap_content"  
  63.                 android:layout_height="46dp"  
  64.                 android:layout_marginLeft="2dp"  
  65.                 android:layout_marginRight="3dp"  
  66.                 android:layout_weight="1"  
  67.                 android:background="@drawable/widget_keypad_digit"  
  68.                 android:gravity="center"  
  69.                 android:text="2"  
  70.                 android:textSize="22sp" >  
  71.             </Button>  
  72.    
  73.             <Button  
  74.                 android:id="@+id/digitkeypad_3"  
  75.                 android:layout_width="wrap_content"  
  76.                 android:layout_height="46dp"  
  77.                 android:layout_marginLeft="2dp"  
  78.                 android:layout_marginRight="4dp"  
  79.                 android:layout_weight="1"  
  80.                 android:background="@drawable/widget_keypad_digit"  
  81.                 android:gravity="center"  
  82.                 android:text="3"  
  83.                 android:textSize="22sp" >  
  84.             </Button>  
  85.         </LinearLayout>  
  86.    
  87.         <LinearLayout  
  88.             android:layout_width="fill_parent"  
  89.             android:layout_height="wrap_content"  
  90.             android:orientation="horizontal" >  
  91.    
  92.             <Button  
  93.                 android:id="@+id/digitkeypad_4"  
  94.                 android:layout_width="wrap_content"  
  95.                 android:layout_height="46dp"  
  96.                 android:layout_marginLeft="4dp"  
  97.                 android:layout_marginRight="2dp"  
  98.                 android:layout_weight="1"  
  99.                 android:background="@drawable/widget_keypad_digit"  
  100.                 android:text="4"  
  101.                 android:textSize="22sp" >  
  102.             </Button>  
  103.    
  104.             <Button  
  105.                 android:id="@+id/digitkeypad_5"  
  106.                 android:layout_width="wrap_content"  
  107.                 android:layout_height="46dp"  
  108.                 android:layout_marginLeft="2dp"  
  109.                 android:layout_marginRight="3dp"  
  110.                 android:layout_weight="1"  
  111.                 android:background="@drawable/widget_keypad_digit"  
  112.                 android:text="5"  
  113.                 android:textSize="22sp" >  
  114.             </Button>  
  115.    
  116.             <Button  
  117.                 android:id="@+id/digitkeypad_6"  
  118.                 android:layout_width="wrap_content"  
  119.                 android:layout_height="46dp"  
  120.                 android:layout_marginLeft="2dp"  
  121.                 android:layout_marginRight="4dp"  
  122.                 android:layout_weight="1"  
  123.                 android:background="@drawable/widget_keypad_digit"  
  124.                 android:text="6"  
  125.                 android:textSize="22sp" >  
  126.             </Button>  
  127.         </LinearLayout>  
  128.    
  129.         <LinearLayout  
  130.             android:layout_width="fill_parent"  
  131.             android:layout_height="wrap_content"  
  132.             android:orientation="horizontal" >  
  133.    
  134.             <Button  
  135.                 android:id="@+id/digitkeypad_7"  
  136.                 android:layout_width="80dp"  
  137.                 android:layout_height="46dp"  
  138.                 android:layout_marginLeft="4dp"  
  139.                 android:layout_marginRight="2dp"  
  140.                 android:layout_weight="1"  
  141.                 android:background="@drawable/widget_keypad_digit"  
  142.                 android:text="7"  
  143.                 android:textSize="22sp" >  
  144.             </Button>  
  145.    
  146.             <Button  
  147.                 android:id="@+id/digitkeypad_8"  
  148.                 android:layout_width="80dp"  
  149.                 android:layout_height="46dp"  
  150.                 android:layout_marginLeft="2dp"  
  151.                 android:layout_marginRight="3dp"  
  152.                 android:layout_weight="1"  
  153.                 android:background="@drawable/widget_keypad_digit"  
  154.                 android:text="8"  
  155.                 android:textSize="22sp" >  
  156.             </Button>  
  157.    
  158.             <Button  
  159.                 android:id="@+id/digitkeypad_9"  
  160.                 android:layout_width="80dp"  
  161.                 android:layout_height="46dp"  
  162.                 android:layout_marginLeft="2dp"  
  163.                 android:layout_marginRight="4dp"  
  164.                 android:layout_weight="1"  
  165.                 android:background="@drawable/widget_keypad_digit"  
  166.                 android:text="9"  
  167.                 android:textSize="22sp" >  
  168.             </Button>  
  169.         </LinearLayout>  
  170.    
  171.         <LinearLayout  
  172.             android:layout_width="fill_parent"  
  173.             android:layout_height="wrap_content"  
  174.             android:orientation="horizontal" >  
  175.    
  176.             <Button  
  177.                 android:id="@+id/digitkeypad_c"  
  178.                 android:layout_width="80dp"  
  179.                 android:layout_height="46dp"  
  180.                 android:layout_marginLeft="4dp"  
  181.                 android:layout_marginRight="2dp"  
  182.                 android:layout_weight="1"  
  183.                 android:background="@drawable/keyboardclear"  
  184.                 android:text=""  
  185.                 android:textSize="22sp" >  
  186.             </Button>  
  187.    
  188.             <Button  
  189.                 android:id="@+id/digitkeypad_0"  
  190.                 android:layout_width="80dp"  
  191.                 android:layout_height="46dp"  
  192.                 android:layout_marginLeft="2dp"  
  193.                 android:layout_marginRight="3dp"  
  194.                 android:layout_weight="1"  
  195.                 android:background="@drawable/widget_keypad_digit"  
  196.                 android:text="0"  
  197.                 android:textSize="22sp" >  
  198.             </Button>  
  199.    
  200.             <Button  
  201.                 android:id="@+id/digitkeypad_ok"  
  202.                 android:layout_width="80dp"  
  203.                 android:layout_height="46dp"  
  204.                 android:layout_marginLeft="2dp"  
  205.                 android:layout_marginRight="4dp"  
  206.                 android:layout_weight="1"  
  207.                 android:background="@drawable/keyboardok"  
  208.                 android:text=""  
  209.                 android:textSize="22sp" >  
  210.             </Button>  
  211.         </LinearLayout>  
  212.     </LinearLayout>  
  213.    
  214. </LinearLayout>  

鍵盤布局文件截圖如下:

Copyright © Linux教程網 All Rights Reserved