2017-02-22 57 views
0

現在、ソフトキーボードによるユーザー入力を受け取ることができるAndroidアプリケーションを開発しています。それは私が他の言語に変更することができなかったこと、私のデフォルト言語(なしAndroidのGoogle IME

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

とGoogle 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を呼び出す必要はありません。ラベル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() { 

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

多くの時間を無駄にして、これが他の人に役立つことを願っています。

関連する問題