2017-02-22 11 views
0

현재 소프트 키보드로 사용자 입력을 수신 할 수있는 Android 애플리케이션을 개발 중입니다. 그건 내가 다른 언어로 변경할 수 있음을 의미 나의 기본 언어 (없이Android의 Google IME

((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); 

그리고 구글 IME 디스플레이 :하지만 아래의 코드를 사용하는 경우에만 영어 키보드가 내 키보드가 표시 몇 가지 문제가있다 탭을 선택하지 않기 때문에)하지만 전체 기사를 검색하면 코드로 IME 언어를 변경할 방법이없는 것 같습니다.

LIBGDX는 UI 요소 (TextField)가 아니며 Android에서 direclty를 호출해도 기본 언어 (중국어)로 Google IME가 표시 될 수 있습니다. 그러나 시스템 IME를 사용하면 예상대로 작동 할 수 있습니다.

다른 명확한 문제로 다른 앱에서 Google IME를 아무런 문제없이 사용할 수 있으며 InputMethodManager를 호출하는 데 사용한 코드도 게시 할 수 있습니다.

package my.package; 
import android.app.Service; 
import android.content.Context; 
import android.content.res.Configuration; 
import android.content.res.Resources; 
import android.os.Build; 
import android.os.Handler; 
import android.os.LocaleList; 
import android.os.Looper; 
import android.text.InputType; 
import android.util.DisplayMetrics; 
import android.view.inputmethod.InputMethodManager; 
import android.view.inputmethod.InputMethodSubtype; 
import android.widget.EditText; 

import java.util.Locale; 

import my.package.Debugger; 


public final class AndroidKeyboardAdapter implements KeyboardAdapter{ 
    InputMethodManager imm; 
    Context context; 
    EditText text; 
    public AndroidKeyboardAdapter(Context context) { 
     this.context = context; 
     imm = (InputMethodManager)context.getSystemService(Service.INPUT_METHOD_SERVICE); 
    } 

    public void showKeyboard() { 
     text = new EditText(context); 

     Locale locale; 
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { 
      locale = context.getResources().getConfiguration().getLocales().get(0); 
      for(int i = 0; i < context.getResources().getConfiguration().getLocales().size();i++) 
       Debugger.LogInConsole(context.getResources().getConfiguration().getLocales().get(i).getCountry()); // show TW 
     } else{ 
      //noinspection deprecation 
      locale = context.getResources().getConfiguration().locale; 
      Debugger.LogInConsole(locale.getCountry()); // not doing anything 
     } 
     Debugger.LogInConsole(Locale.getDefault().toString()); //show zh_tw 


     ((InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE)).toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY); 
    } 

    public void hideKeyboard() { 
     imm.hideSoftInputFromWindow(text.getWindowToken(), 0); 
    } 


    public void onResume() { 
     text.requestFocus(); 

     text.postDelayed(new Runnable() { 
      @Override 
      public void run() { 
       // TODO Auto-generated method stub 
       imm.showSoftInput(text, 0); 
      } 
     },200); 
    } 

    @Override 
    public String getText() { 
     return text.getText().toString(); 
    } 
} 

는 또한 IMM에 그 LIBGDX 과정의 소스 코드를 제공합니다

@Override 
    public void setOnscreenKeyboardVisible (final boolean visible) { 
     handle.post(new Runnable() { 
      public void run() { 
       InputMethodManager manager = (InputMethodManager)context.getSystemService(Context.INPUT_METHOD_SERVICE); 
       if (visible) { 
        View view = ((AndroidGraphics)app.getGraphics()).getView(); 
        view.setFocusable(true); 
        view.setFocusableInTouchMode(true); 
        manager.showSoftInput(((AndroidGraphics)app.getGraphics()).getView(), 0); 
       } else { 
        manager.hideSoftInputFromWindow(((AndroidGraphics)app.getGraphics()).getView().getWindowToken(), 0); 
       } 
      } 
     }); 
    } 

답변

0

편집 : 는 상대적 issue 발견하고, 보고서에 따르면, LIBGDX는 경우, 영어 개발자가 특정 구성을 당신은 다른 언어 개발자입니다. TextField UI를 사용하지 말고 직접 IMM을 호출하면됩니다. 아래의 코드를 Label UI와 함께 사용하면 모든 것이 정상입니다 ...

label.addListener(new ClickListener() { 
     @Override 
     public void clicked(InputEvent event, float x, float y) { 
      Gdx.input.getTextInput(new Input.TextInputListener() { 
       @Override 
       public void input(String text) { 
        label.setText(text); 
        Debugger.LogInConsole(text); 
       } 

       @Override 
       public void canceled() { 

       } 
      },"","",""); 
     } 
    }); 

소스 코드를 읽는 데 많은 시간을 낭비하고 다른 사람들에게 도움이되기를 바랍니다.