Android 키보드 의 중 영문 적합 실현

안 드 로 이 드 프로젝트 개발 을 진행 할 때 중국어 입력 과 영어 입력 이 전환 되 는 경우 가 많 습 니 다.이 내용 은 안 드 로 이 드 에서 영어 키 보드 를 자동 으로 식별 하 는 기능 을 가 르 칩 니 다.
영어 환경 에서 암호 상자 글꼴 과 일반 글꼴 이 일치 하지 않 는 문제
1.xml 에서 input Type 속성 또는 password 속성 을 설정 할 수 없습니다.
2.중국어 환경 에서 input Type 설정 가능
3.영어 에 어 울 리 면 자바 코드 에서 만 설정 할 수 있 습 니 다.

android 개발 EditText 입력 시 디지털 입력 키보드 팝 업(영어 환경 에 적합)
우선 숫자 만 입력 할 수 있 도록 설정

<EditText
android:id="@+id/second_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="1234567890"
android:maxLength="6"
android:paddingLeft="@dimen/dp_20"
android:singleLine="true"
android:textSize="@dimen/sp_14"/>
포 인 트 는...
android:digits="1234567890"
EditText 에서 android:digits 속성의 역할
어떤 문 자 를 입력 할 수 있 는 지 설정 합 니 다.예 를 들 어'1234567890.+-*/%()'
코드 에 입력 형식 을 설정 합 니 다:

secondPassword.setInputType(EditorInfo.TYPE_CLASS_PHONE);//    
secondPassword.setTransformationMethod(new PasswordTransformationMethod());//  
이 EditText 가 초점 을 맞 추 면 디지털 입력 법의 아 날로 그 키보드 가 팝 업 됩 니 다.
xml 에 input Type 속성 을 설정 하면 됩 니 다.
1.API 에 inputType 의 값 이 어떤 것 을 포함 하 는 지 열거 합 니 다.

android:inputType=”none”
android:inputType=”text”
android:inputType=”textCapCharacters”     
android:inputType=”textCapWords”      
android:inputType=”textCapSentences”         
android:inputType=”textAutoCorrect”     
android:inputType=”textAutoComplete”     
android:inputType=”textMultiLine”     
android:inputType=”textImeMultiLine”      (    )
android:inputType=”textNoSuggestions”    
android:inputType=”textUri”   
android:inputType=”textEmailAddress”       
android:inputType=”textEmailSubject”     
android:inputType=”textShortMessage”   
android:inputType=”textLongMessage”    
android:inputType=”textPersonName”   
android:inputType=”textPostalAddress”   
android:inputType=”textPassword”   
android:inputType=”textVisiblePassword”     
android:inputType=”textWebEditText”          
android:inputType=”textFilter”       
android:inputType=”textPhonetic”     
//    
android:inputType=”number”   
android:inputType=”numberSigned”        
android:inputType=”numberDecimal”          
android:inputType=”phone”     
android:inputType=”datetime”     
android:inputType=”date”     
android:inputType=”time”     
2、Enter 키 아이콘 설정
우리 가 EditText 에서 입력 을 완 료 했 을 때 입력 한 내용 을 키워드 로 검색 하려 면'완성'아이콘 의 Enter 버튼 을 눌 러 야 한다 고 상상 해 보 세 요.이것 은 좋 은 사용자 체험 디자인 에 부합 되 지 않 습 니 다.그렇다면 엔 터 버튼 아이콘 을 어떻게 바 꿀 까요?
Android 는 이 기능 을 실현 하기 위해 android:imeOptions 를 제공 합 니 다.
android:imeOptions 의 상용 매개 변 수 는 다음 과 같 습 니 다.
normal(일반),
actionUnspecified(지정 되 지 않 음),
actionNone(동작 없 음),
actiongo(이동),
actionSearch(검색),
actionSend(발송),
actionNext(다음),
actionDone(완료),
flagNoExtractUi,flagNoAccessory Action,flagNoEnterAction 등 대응 하 는 Enter 키
아이콘 은 다음 과 같 습 니 다:

3.소프트 키보드 인 터 랙 션 스타일 설정
키보드 팝 업 은 화면 을 상단 으로 누 르 거나 화면 을 직접 덮어 야 할 때 도 있다.AndroidManifest.xml 에 대응 하 는 Activity 에 이 속성 을 추가 할 수 있 습 니 다.
android:windowSoftInputMode="인자"
매개 변수 에 대한 자세 한 내용 은 다음 과 같 습 니 다.여러 매개 변수 사이 에'|'로 구분 할 수 있 습 니 다.
【A】stateUnspecified:소프트 키보드 의 상 태 는 지정 되 지 않 았 습 니 다.시스템 은 적당 한 상 태 를 선택 하거나 테마 에 의존 하 는 설정 을 선택 할 것 입 니 다.
【B】stateUnchanged:이 activity 가 나타 날 때 소프트 키 보드 는 이전 activity 의 상 태 를 유지 합 니 다.숨 기 든 표시 하 든.
【C】stateHidden:사용자 가 activity 를 선택 할 때 소프트 키 보드 는 항상 숨겨 집 니 다.
【D】stateAlwaysHidden:이 Activity 주 창 이 초점 을 가 져 올 때 소프트 키보드 도 항상 숨겨 집 니 다.
[E]stateVisible:소프트 키 보드 는 보통 볼 수 있 습 니 다.
【F】stateAlwaysVisible:사용자 가 activity 를 선택 할 때 소프트 키보드 가 항상 표시 되 는 상태
【G】adjustUnspecified:기본 설정 은 시스템 에서 숨 길 지 표시 할 지 결정 합 니 다.
【H】adjustResize:이 액 티 비 티 는 소프트 키보드 의 공간 을 남기 기 위해 항상 화면의 크기 를 조정 합 니 다.
【I】adjustPan:현재 창의 내용 은 키보드 로 덮어 쓰 지 않 고 사용자 가 입력 한 부분 을 항상 볼 수 있 도록 자동 으로 이동 합 니 다.
EditText 는 기본적으로 소프트웨어 키 보드 를 꺼 내지 않 습 니 다.
방법 1:
AndroidMainfest.xml 에서 어떤 activity 를 선택 하고 windowSoftInputMode 속성 을 adjustUnspecified|state Hidden 으로 설정 합 니 다.
예 를 들 면:

<activity android:name=".Main"
  android:label="@string/app_name"
  android:windowSoftInputMode="adjustUnspecified|stateHidden"
  android:configChanges="orientation|keyboardHidden">
  <intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
  </intent-filter>
</activity>
방법 2:
EditText 의 초점 을 잃 게 하고 EditText 의 clearFocus 방법 을 사용 합 니 다.
예 를 들 면:

EditText edit=(EditText)findViewById(R.id.edit);
edit.clearFocus();
방법 3:
Android 입력 창 강제 숨 기기
예 를 들 면:

EditText edit=(EditText)findViewById(R.id.edit);
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edit.getWindowToken(),0);
4.입력 한 소문 자 를 대문자 로 자동 변환
자동 으로 대문자 로 전환 하 다.하지만 대문자 로 만 표시 되 고 소문 자로 저장 되 어 있다.

class InputLowerToUpper extends ReplacementTransformationMethod{ 
  @Override 
  protected char[] getOriginal() { 
   char[] lower = { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' }; 
   return lower; 
  } 
  @Override 
  protected char[] getReplacement() { 
   char[] upper = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' }; 
   return upper; 
  } 
 } 
editText.setTransformationMethod(new InputLowerToUpper());
안 드 로 이 드:inputType="textCapCharacters"를 설정 하면 되 지만 비밀번호 키 보드 를 한 개 로 사용 할 수 없습니다.

//                          
addressText.addTextChangedListener(new TextWatcher() { 
  @Override 
  public void onTextChanged(CharSequence s, int start, int before, int count) { 
   // TODO Auto-generated method stub 
   addressText.removeTextChangedListener(this);//         
   addressText.setText(s.toString().toUpperCase());//   
   addressText.setSelection(s.toString().length());//         
   addressText.addTextChangedListener(this);//    
//   licensePlateNumber = addressText.getText().toString().trim(); 
  } 
  @Override 
  public void beforeTextChanged(CharSequence s, int start, int count, int after) { 
   // TODO Auto-generated method stub 
  } 
  @Override
  public void afterTextChanged(Editable arg0) {
   // TODO Auto-generated method stub 
  } 
 });

좋은 웹페이지 즐겨찾기