Tải bản đầy đủ (.pptx) (23 trang)

android development introduction chương 7 b android hard & soft keyboards

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (573.36 KB, 23 trang )




 
!"#$!
%&'(()*'((+ ,-##$
.+/)*(*+)01/)(*(*+


233$$4 35$ 
7B
'
/$67.6

'
0$849:Input Method Framework (IMF)$


 99: ;"<9 - ;3;4-
4=;>49-:4

"-

44%9-

;9%-

4?
@
/$67.6



@
%>49:49:;44$
HTC – G1
%,;5A44B
"
Samsung
!; "
HTC - Magic
!;
"
C
/$67.6

C
.!D;:;
4$
.:;"-
A.!EB; 
;$

E
E5
8
/$67.6

8
Telling Android what data to expect
5F;44 54:5G
android:inputType=“ ”
editTextBox.setRawInputType(int)

;";:45G$
;%:4%; 45$
H!#
I
1
/$67.6

1
Constant Value Description
none 0x00000000 There is no content type. The text is not editable.
text 0x00000001 Just plain old text.
textCapCharacters 0x00001001 Can be combined with text and its variations to request capitalization of all characters.
textCapWords 0x00002001 Can be combined with text and its variations to request capitalization of the first character of every word.
textCapSentences 0x00004001 Can be combined with text and its variations to request capitalization of the first character of every
sentence.
textAutoCorrect 0x00008001 Can be combined with text and its variations to request auto-correction of text being input.
Android:inputType Values
/
/$67.6

/
Constant Value Description
textAutoComplete 0x00010001 Can be combined with text and its variations to specify that this field will be doing its own auto-
completion and talking with the input method appropriately.
textMultiLine 0x00020001 Can be combined with text and its variations to allow multiple lines of text in the field. If this flag is not
set, the text field will be constrained to a single line.
textImeMultiLine 0x00040001 Can be combined with text and its variations to indicate that though the regular text view should not be
multiple lines, the IME should provide multiple lines if it can.
Android:inputType Values
)

/$67.6

)
Constant Value Description
textUri 0x00000011 Text that will be used as a URI.
textEmailAddress 0x00000021 Text that will be used as an e-mail address.
textEmailSubject 0x00000031 Text that is being supplied as the subject of an e-mail.
textShortMessage 0x00000041 Text that is the content of a short message.
textLongMessage 0x00000051 Text that is the content of a long message.
textPersonName 0x00000061 Text that is the name of a person.
textPostalAddress 0x00000071 Text that is being supplied as a postal mailing address.
textPassword 0x00000081 Text that is a password.
textVisiblePassword 0x00000091 Text that is a password that should be visible.
textWebEditText 0x000000a1 Text that is being supplied as text in a web form.
Android:inputType Values
+
/$67.6

+
Constant Value Description
textFilter 0x000000b1 Text that is filtering some other data.
textPhonetic 0x000000c1 Text that is for phonetic pronunciation, such as a phonetic name field in a contact entry.
number 0x00000002 A numeric only field.
numberSigned 0x00001002 Can be combined with number and its other options to allow a signed number.
numberDecimal 0x00002002 Can be combined with number and its other options to allow a decimal (fractional) number.
phone 0x00000003 For entering a phone number.
datetime 0x00000004 For entering a date and time.
date 0x00000014 For entering a date.
time 0x00000024 For entering a time.
Android:inputType Values

0(
/$67.6

0(
Example1: 7%5J!"K#$!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/widget31"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffcccccc"
android:orientation="vertical"
xmlns:android=" >
<TextView
android:id="@+id/caption"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#ff0000ff"
android:text="inputType: text|textCapWords"
android:textStyle="bold"
android:textSize="22sp" />
<EditText
android:id="@+id/editTextBox"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10px"
android:textSize="18sp"
android:inputType="text|textCapWords" />
</LinearLayout>
Mul'pletypes : 4

4 $7LM | 
9$
.5 5"
-
9%
4;
00
/$67.6

00
Example1: 7%5J!"K#$!
%E5"
;%N.#2
G2;4
 94#O,EP44 ;$
%"44
%%;7NNEP4-#O,EP42$
0'
/$67.6

0'
Example2: 7%J!K&'K(!
0$ " $
'$ .%)"$
@$ O 454$
C$ number|numberSigned44%$
8$ numberDecimal44 $
 E5G editTextBox-.I4;4*9 
 %4 
editTextBox.setRawInputType(

android.text.InputType.TYPE_CLASS_PHONE BQ
0@
/$67.6

0@
Example2: 7%
J!*!

""$

44R:G49$

444 )$
Example3: 7%
J!+!
":44
4  
42-@
0C
/$67.6

0C
Example4: 7%J!!
":
4,9
% 4
( ) . / Pause Wait # - +
08
/$67.6


08
Example5: 7%J!!
" 4$
O%4*4: 4$
,44"%9444ABC44 "am
pm;$
01
/$67.6

01
Example6: 7%J!!
" 4$
O%44;$
E5 :
0'/@0/'(00
0'-@0-'(00
0'$@0$'(00
0/
/$67.6

0/
Disable So8 Keyboarding on an EditText View
 -.E55$disable49:"E5
-4;
txtBox.setInputType( InputType.TYPE_NULL );
S A:4B
txtBox.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View arg0, MotionEvent arg1) {
// return true to consume the touch event without

// allowing virtual keyboard to be called
return true;
}
});
0)
/$67.6

0)
Close So8Keyboard Window / Hide So8Keyboard
O4- 4"%;BackArrow"%:;%4 
InputMethodManager imm =
(InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

imm.hideSoftInputFromWindow (theEditTextField.getWindowToken(), 0);
0+
/$67.6

0+
TextWatcher Control
 -.Editable5$:onKeyListener4:;49 ;
"Q;,Virtual Keyboard$
9 24E4TextWatcher 4;E5
4%$
  :TextWatcher
public void 5% (Editable ,45)
public void :5% ( … )
public void 5% ( … )
'(
/$67.6


'(
Example 7: TextWatcher Demo
EditText uses .addTextChangedListener
IMF sugges'ons
'0
/$67.6

'0
Example 7: TextWatcher Demo
TU5 J!./!'0!1)2!34
T##5 J!"555,55!
9J! !
V;J!67!
V%J!67!
4"%J!89!
W
TE5
J!:;5!
V;J!67!
V%J!7!
V %J!./!
%J!<!
5J!!
3W

T5F;
J!:;5'!
V;J!67!
V%J!7!
V %J!./!

%J!<!
4"%J!89////9!
5J!!
3W
T3##W
''
/$67.6

''
Example 7: TextWatcher Demo
33 : EH,EP4
package cis493.keyboarding;
?
public class TextWatcherDemo extends Ac'vity {
E55.Q
5F;5!%Q
"J(Q
XO
public void  (Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 F;AP$$=>
 5!%JA5F;BGF;.AP$$'=>
 5.JAE5BGF;.AP$$=>
5.$5%#Anew TextWatcher() {
public void 5% (Editable ,45) {
% %JY4YZ5.$%5AB$%AB$%ABZYYZ,45$%ABQ
5!%$5A %BQ
[
public void :5% (CharSequence arg0, int arg1, int arg2, int arg3) {
33$ "5A%495AB-YYZ%(-0B$;ABQ

[
public void 5% (CharSequence arg0, int arg1, int arg2, int arg3) {
33$ "5A%495AB-YOYZ%(-0B$;ABQ
[
 [BQ335%#
[33
[
'@
/$67.6

'@
\9U

×